Fix stale PID race in ConsumerRegistry.unregister_name/1#3979
Fix stale PID race in ConsumerRegistry.unregister_name/1#3979
Conversation
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3979 +/- ##
===========================================
+ Coverage 75.75% 88.74% +12.98%
===========================================
Files 11 25 +14
Lines 693 2425 +1732
Branches 172 612 +440
===========================================
+ Hits 525 2152 +1627
- Misses 167 271 +104
- Partials 1 2 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
dbb2f9f to
44ce5d6
Compare
Claude Code ReviewSummaryThis PR fixes the What's Working Well
Issues FoundNo outstanding issues. Issue ConformanceIssue #3864 is well-specified with root cause analysis, three affected code paths, and a proposed fix. This PR implements a strictly better version of the proposed fix (atomic Previous Review StatusAll issues resolved:
Review iteration: 2 | 2026-03-16 |
The previous no-op implementation left stale PIDs in the ETS table. A naive lookup-then-delete fix would still be racey because the entry could be overwritten between the lookup and delete. Using :ets.match_delete/2 atomically deletes the entry only if the pid matches the calling (dying) process. Closes #3864 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c622202 to
537c8dd
Compare
|
Found 1 test failure on Blacksmith runners: Failure
|
|
@alco the reason for the no-op unregister call was to handle race conditions between the consumer registry and the shape log collector. If you just remove the registry entry when the pid terminates but before you remove the shape from the SLC, then the SLC could receive an operation for that shape, see that the consumer process isn't there and start a new process for it. Then the SLC gets the "remove shape" for that new process and you're left with an orphan process. |
Summary
unregister_name/1with an atomic:ets.match_delete/2that removes the ETS entry only if the pid matches the calling (dying) processmatch_deleteis atomicCloses #3864
Test plan
mix test test/electric/shapes/consumer_registry_test.exs— 16 tests pass (3 new)🤖 Generated with Claude Code