Skip to content

Keep a nested reader pause when resume refills the queue - #512

Closed
gyanu2507 wants to merge 1 commit into
NabuCasa:mainfrom
gyanu2507:fix/reentrant-reader-pause
Closed

gyanu2507 wants to merge 1 commit into
NabuCasa:mainfrom
gyanu2507:fix/reentrant-reader-pause

Conversation

@gyanu2507

@gyanu2507 gyanu2507 commented Sep 24, 2026 •

Copy link
Copy Markdown

Fixes #511.

_pause_or_resume_reader called the pause/resume callback and only then stored _reader_paused. Resuming the reader can synchronously write enough to cross the high watermark and ask for a pause again. That nested call still saw the old flag, treated the pause as a no-op, and left the reader running. The output queue then overflows and the channel closes, which stalls a large streamed response.

The flag is updated before the callback, and restored if the callback raises, so a failed callback does not leave the flag ahead of the reader.

Test plan

  • test_reentrant_resume_keeps_nested_pause
  • test_concurrent_pause_resume_race_condition
  • test_flow_control_allow_multiple_pause_resume

_pause_or_resume_reader called the callback before updating _reader_paused. A resume that synchronously crosses the high watermark asked to pause again while the flag still said paused, so the pause was dropped and the stream kept going.
@gyanu2507

Copy link
Copy Markdown
Author

Closing this to narrow my open-source work to fewer projects. Anyone is welcome to pick the change up if it's useful.

@gyanu2507 gyanu2507 closed this Nov 9, 2026
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.

Large streamed responses stall mid-transfer: re-entrant resume in _pause_or_resume_reader drops a nested pause (regression from #427)

1 participant