fix: serialize hub send so multi-instrument create does not race (#126) - #127
Merged
Merged
Conversation
v4.1.1: lock AsyncHubConnection.send, subscribe all contracts once before starting feeds, skip start_realtime_feed re-subscribe when the contract is already tracked, and await async heartbeat send.
Track live hub subscriptions separately from the restore desired-set so a failed subscribe cannot start a feed with no Gateway subscription.
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
Fixes #126:
TradingSuite.create(["MNQ", "MES"])flaked withSubscription returned Falseandcoroutine 'AsyncHubConnection.send' was never awaitedbecause parallel instrument init piledsend()onto one shared pysignalr market hub.Changes
AsyncHubConnection.send()with anasyncio.Lock.subscribe_market_data([...])call, then start feeds (do notgatherper-instrument subscribe).start_realtime_feedskips a second hub subscribe when the contract is already tracked.awaitasync hubsend()instead of dropping the coroutine viarun_in_executor._subscription_lockfor list mutations.Reconnect restore still re-sends
SubscribeContract*because skip is only instart_realtime_feed, not insubscribe_market_data.Tests
Local:
uv run pytest tests/ --ignore=tests/benchmarks/→ 3166 passed, 2 skipped.New coverage:
send()never overlapssubscribe_market_dataserializes sendstart_realtime_feeddoes not re-subscribe when already trackedsend()Release
This PR is the v4.1.1 release candidate. After CI is green, squash-merge, tag
v4.1.1, GitHub Release, and PyPI publish.