fix(realtime): skip bounded-stats sweep on data manager teardown (#98) - #147
Merged
Merged
Conversation
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.
This was referenced Sep 26, 2026
Merged
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.
Refs #98
Summary
RealtimeDataManager.cleanup()now stops the in-sessionCleanupSchedulerdirectly instead of callingcleanup_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.CleanupScheduleris unchanged;cleanup_bounded_statistics()stays public for explicit mid-session sweeps.TradingSuite.disconnect()already awaitsrealtime.disconnect()(stops both hubs and joins each hubrun()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.Tests
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 withasyncio.wait_fortimeouts).tests/realtime_data_manager/test_data_core_comprehensive.py.Docs
Note: the Windows
0xc0000374crash itself cannot be reproduced in this environment, so this PR references #98 rather than closing it.