fix: race conditions in keepAlive() and wsServe() for futures, options, delivery#805
Open
DukeDeSouth wants to merge 2 commits into
Open
fix: race conditions in keepAlive() and wsServe() for futures, options, delivery#805DukeDeSouth wants to merge 2 commits into
DukeDeSouth wants to merge 2 commits into
Conversation
…s, delivery The lastResponse variable in keepAlive() is a time.Time shared between the ping handler goroutine and the ticker goroutine without sync. The base package was already fixed with atomic.Int64, but futures, options, and delivery still had the original racy code. This applies the same atomic pattern to all three remaining packages. Also fixes a previously unreported race on the silent bool in wsServe() across all four packages including the base. Fixes ccxt#704 Made-with: Cursor
TestKeepAliveNoRace spins up a real WebSocket server that sends rapid pings while a short-interval ticker reads lastResponse — reproduces the data race on the original code (confirmed: FAIL without the fix). TestWsSilentNoRace exercises the stopC → silent → ReadMessage path to cover the second race. Both pass consistently with -race -count=3 after the atomic fix. Made-with: Cursor
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.
Fixes #704.
The
lastResponsevariable inkeepAlive()is atime.Timestruct shared between the ping handler goroutine (writer) and the ticker goroutine (reader) without synchronization. The base packagev2/websocket.gowas already fixed withatomic.Int64, butv2/futures,v2/options, andv2/deliverystill had the original racy code.This applies the same atomic pattern to all three remaining packages. I also noticed a previously unreported race on the
silentbool inwsServe()— it's written in one goroutine and read in another without sync. Fixed that across all four packages (including the base) usingatomic.Int32.All existing tests pass with
-raceenabled. No API changes, no new dependencies, no behavior change.Made with Cursor