Skip to content

fix: bound get_session_data so on_bar cannot hang (#137) - #138

Merged
TexasCoding merged 1 commit into
mainfrom
fix/137-get-session-data-hang
Sep 4, 2026
Merged

TexasCoding merged 1 commit into
mainfrom
fix/137-get-session-data-hang

Conversation

@TexasCoding

Copy link
Copy Markdown
Owner

Summary

Fixes #137. DataManager.get_session_data("1min"|"5min", SessionType.RTH) could wait forever on the bar-cache lock with no exception, which pinned on_bar and dropped later NEW_BAR events 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():

  • Readers never waited for an active or waiting writer (the lock was not a real RW lock).
  • Writers busy-waited on _reader_count with no timeout.
  • get_data returned a live DataFrame and get_session_data had 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 or None.
  • session_type optional on get_session_data() (uses session_config).
  • resolve_session_product() maps CON.F.US.MNQ.H26 / MNQH26 to session calendars.
  • Config: data_lock_timeout, session_data_timeout.
  • Version 4.2.1. Docs/README/CHANGELOG updated; 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::TestResolveSessionProduct

Local: uv run pytest -m "unit and not slow" → 2717 passed. ruff check src/ and mypy src/ clean.

After merge

Tag v4.2.1 and publish to PyPI (this PR is the version bump).

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.
@TexasCoding
TexasCoding merged commit 4eb0897 into main Sep 4, 2026
7 checks passed
@TexasCoding
TexasCoding deleted the fix/137-get-session-data-hang branch September 4, 2026 03:54
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.

get_session_data(tf, SessionType.RTH) hangs indefinitely (7–75+ min) with no exception — blocks on_bar

1 participant