Skip to content

fix: serialize hub send so multi-instrument create does not race (#126) - #127

Merged
TexasCoding merged 2 commits into
mainfrom
fix/issue-126-multi-instrument-hub-send-race
Aug 30, 2026
Merged

fix: serialize hub send so multi-instrument create does not race (#126)#127
TexasCoding merged 2 commits into
mainfrom
fix/issue-126-multi-instrument-hub-send-race

Conversation

@TexasCoding

Copy link
Copy Markdown
Owner

Summary

Fixes #126: TradingSuite.create(["MNQ", "MES"]) flaked with Subscription returned False and coroutine 'AsyncHubConnection.send' was never awaited because parallel instrument init piled send() onto one shared pysignalr market hub.

Changes

  • Serialize AsyncHubConnection.send() with an asyncio.Lock.
  • Subscribe every contract in one subscribe_market_data([...]) call, then start feeds (do not gather per-instrument subscribe).
  • start_realtime_feed skips a second hub subscribe when the contract is already tracked.
  • Health-monitor heartbeats await async hub send() instead of dropping the coroutine via run_in_executor.
  • Market subscribe/unsubscribe take _subscription_lock for list mutations.
  • Bump to v4.1.1 (PATCH). Changelog, README, docs, examples, and User-Agent updated.

Reconnect restore still re-sends SubscribeContract* because skip is only in start_realtime_feed, not in subscribe_market_data.

Tests

Local: uv run pytest tests/ --ignore=tests/benchmarks/3166 passed, 2 skipped.

New coverage:

  • concurrent hub send() never overlaps
  • concurrent subscribe_market_data serializes send
  • start_realtime_feed does not re-subscribe when already tracked
  • suite create subscribes once (both contracts) then starts feeds
  • heartbeat awaits async send()

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.

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.
@TexasCoding
TexasCoding merged commit a13dd47 into main Aug 30, 2026
7 checks passed
@TexasCoding
TexasCoding deleted the fix/issue-126-multi-instrument-hub-send-race branch August 30, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-instrument TradingSuite races market-hub send() (Subscription returned False)

1 participant