fix: resolve concurrency bugs in eventbus and webtransport#3518
Open
Sahil-4555 wants to merge 4 commits into
Open
fix: resolve concurrency bugs in eventbus and webtransport#3518Sahil-4555 wants to merge 4 commits into
Sahil-4555 wants to merge 4 commits into
Conversation
Replace the wall-clock TestWildcardSlowConsumerDeadlock with a synctest version that fires the warning timeout on a fake clock, so it runs instantly and cannot flake on a loaded CI runner. Add a close-during- stall test covering the safety valve where closing a subscription releases an emit parked under the wildcard node read lock.
Add a test that the getter returns an independent copy, and a -race test that hammers it during background certificate rotation. Both fail on the unsynchronized getter and pass with the read lock and copy.
lidel
approved these changes
Jun 27, 2026
Member
There was a problem hiding this comment.
Thanks for this. I'd been debugging the same bug myself, so I'm glad you beat me to it :)
I pushed two small test commits on top:
- Moved the eventbus slow-consumer test over to synctest. It runs on a fake clock now, so it's fast and won't flake on CI the way the sleep-based version could.
- Added two tests for
SerializedCertHashes: one checks the getter returns a copy, the other runs it against cert rotation under-race.
@MarcoPolo fwiw lgtm, and Kubo could benefit from this, but your call
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.
Issue
observed two concurrency issues:
slowConsumerTimerpointer. Concurrent emitters raced onReset(), causing the timer to fire only once. One emitter consumed the tick and blocked on the channel, leaving other emitters permanently blocked on<-timer.Ceven after the queue was drained. This hang occurred under a read-lock (RLock), blocking any subscription closure (sub.Close()) or node updates from acquiring a write-lock.SerializedCertHashes()getter read the sharedm.serializedCertHashesslice without acquiring a lock. This caused a read/write data race with the background cert manager thread which updates the slice during certificate rotation. Returning the raw slice by reference also caused slice aliasing, exposing the caller to backing memory being concurrently mutated/resized.Fix
slowConsumerTimerpointer field fromnodeandwildcardNode. The slow consumer warning logic was refactored to use a localtime.Timerallocated on the stack withinemitAndLogError, eliminating shared timer state across concurrent emitters.m.mx.RLock()toSerializedCertHashes()and returned a deep copy of the slice rather than a direct reference to avoid data races and slice aliasing.Tests
TestWildcardSlowConsumerDeadlockinp2p/host/eventbus/basic_test.gowhich simulates a full queue under concurrent emissions to verify that no deadlocks occur and the emitters safely proceed when the queue is drained.