fix(eventstream): Server.publish snapshots subs, releases RLock before I/O#2
Merged
Merged
Conversation
…e I/O Server.publish previously held mu.RLock() across every WriteEvent call. A slow subscriber whose pipe / TCP send buffer was full would block WriteEvent while the read lock was still held, starving every concurrent addSub/removeSub waiting on mu.Lock(). One wedged peer effectively wedged all subscription mutations. Refactor to match the companion broker.publishWith in service.go (P2-003): snapshot the per-topic and "*" subscriber lists under a brief RLock, release the lock, then iterate WriteEvent on the snapshot without holding any lock. Per-write errors are logged. Adds two regression tests: - TestServer_PublishDoesNotBlockOnSlowSubscriber asserts addSub returns within 100ms while a publish is in flight against a blocked-pipe peer. Verified to FAIL deterministically against the old code (addSub blocked >100ms behind slow peer) and PASS after the fix. - TestServer_PublishHandlesSlowSubscriberWithoutDeadlock asserts a fast peer still gets the event promptly, multiple concurrent publishers don't deadlock, and removeSub completes while a slow peer is wedged. Full suite go test -race -count=3 -timeout 180s ./... passes.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Server.publishpreviously heldmu.RLock()across everyWriteEventcall. A slow subscriber whose pipe / TCP send buffer was full would blockWriteEventwhile the read lock was held, starving every concurrentaddSub/removeSubwaiting onmu.Lock(). One wedged peer wedged all subscription mutations.broker.publishWithinservice.go(P2-003 pattern): snapshot per-topic +"*"subscribers under a briefRLock, release, then iterateWriteEventon the snapshot without holding any lock. Per-write errors are logged.zz_server_internals_test.gothat both FAIL deterministically against the old code and PASS after the fix.Test plan
TestServer_PublishDoesNotBlockOnSlowSubscriber— addSub completes <100ms while a publish is mid-flight against a wedged peer. Verified to FAIL 5/5 against old code, PASS 5/5 with the fix.TestServer_PublishHandlesSlowSubscriberWithoutDeadlock— fast peer still receives event; 3 concurrent publishers + removeSub all complete; no deadlock. Verified to FAIL 3/3 against old code, PASS 3/3 with the fix.go test -race -count=3 -timeout 180s ./...— green.