Skip to content

fix(realtime): skip bounded-stats sweep on data manager teardown (#98) - #147

Merged
TexasCoding merged 1 commit into
mainfrom
maint/98-disconnect-teardown-stats
Sep 26, 2026
Merged

TexasCoding merged 1 commit into
mainfrom
maint/98-disconnect-teardown-stats

Conversation

@TexasCoding

Copy link
Copy Markdown
Owner

Refs #98

Summary

  • RealtimeDataManager.cleanup() now stops the in-session CleanupScheduler directly instead of calling cleanup_bounded_statistics(), so no bounded-statistics counter sweep (_cleanup_counters() → get_statistics()) runs during teardown. This is the "secondary hardening" suggested in Heap corruption (0xc0000374) on disconnect: realtime transport stopped after per-context cleanup frees shared state #98: one less concurrent reader of shared state at disconnect.
  • Periodic in-session cleanup via CleanupScheduler is unchanged; cleanup_bounded_statistics() stays public for explicit mid-session sweeps.
  • TradingSuite.disconnect() already awaits realtime.disconnect() (stops both hubs and joins each hub run() task) before per-context cleanup since v4.0.0 (v4.0.0: Revive SDK for the current TopstepX Gateway #102); this PR adds regression tests that lock that ordering in and only updates the comment.
  • Non-breaking: no public API or signature changes.

Tests

  • New: tests/realtime_data_manager/test_cleanup_teardown_stats.py, tests/trading_suite/test_disconnect_teardown_order.py, tests/realtime/test_disconnect_joins_hubs.py (all with asyncio.wait_for timeouts).
  • Updated: tests/realtime_data_manager/test_data_core_comprehensive.py.

Docs

  • CHANGELOG.md (Unreleased → Fixed), docs/changelog.md, README.md, docs/api/data-manager.md, docs/api/trading-suite.md.

Note: the Windows 0xc0000374 crash itself cannot be reproduced in this environment, so this PR references #98 rather than closing it.

RealtimeDataManager.cleanup() stops the in-session CleanupScheduler and
does not call cleanup_bounded_statistics(), so disconnect no longer sweeps
counters that are about to be discarded. Periodic cleanup while the feed
is running is unchanged. TradingSuite.disconnect() already joins both hub
receive tasks before per-instrument data is freed.

Fixes #98.
@TexasCoding
TexasCoding merged commit 54e84a5 into main Sep 26, 2026
7 checks passed
@TexasCoding
TexasCoding deleted the maint/98-disconnect-teardown-stats branch September 26, 2026 21:46
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.

1 participant