fix: resolve concurrency bugs in eventbus and webtransport#3518
Open
Sahil-4555 wants to merge 2 commits into
Open
fix: resolve concurrency bugs in eventbus and webtransport#3518Sahil-4555 wants to merge 2 commits into
Sahil-4555 wants to merge 2 commits into
Conversation
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.