Repository navigation
fix: bound get_session_data so on_bar cannot hang (#137) - #138
Merged
Merged
Conversation
AsyncRWLock now blocks readers while a writer holds or waits, write locks are re-entrant, and acquisition is cancellable. get_session_data copies bars under a 2s lock then filters after release; on timeout it returns the last snapshot instead of blocking the event loop.
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 #137.
DataManager.get_session_data("1min"|"5min", SessionType.RTH)could wait forever on the bar-cache lock with no exception, which pinnedon_barand dropped laterNEW_BARevents while the rest of the process still looked healthy.This is not the silent WebSocket freeze from #97. The hang was inside
get_session_data→get_data→AsyncRWLock.read_lock():_reader_countwith no timeout.get_datareturned a live DataFrame andget_session_datahad no timeout/cancellation path.Changes
AsyncRWLock: condition-based lock, writer preference, re-entrant writes, cancellable acquire, timeouts actually apply.get_data/get_session_data: copy bars under a bounded read lock (defaults 5s / 2s), filter after release. On timeout return the last successful snapshot orNone.session_typeoptional onget_session_data()(usessession_config).resolve_session_product()mapsCON.F.US.MNQ.H26/MNQH26to session calendars.data_lock_timeout,session_data_timeout.SessionType.BOTH(it does not exist) removed from current docs.Tests
tests/utils/test_async_rw_lock.py— reader/writer coordination, timeouts, reentrancy, cancellation.tests/realtime_data_manager/test_get_session_data_hang.py— timeout while write lock held, last-known snapshot, no lock held during filter, contract-id product resolve, cancellation.tests/unit/test_session_filter.py::TestResolveSessionProductLocal:
uv run pytest -m "unit and not slow"→ 2717 passed.ruff check src/andmypy src/clean.After merge
Tag
v4.2.1and publish to PyPI (this PR is the version bump).