Skip to content

Add tests for asyncio _FlowControlMixin exception handling in pause_writing #150361

Closed

Description

@azibom

Add tests for exception handling in _FlowControlMixin._maybe_pause_protocol

The _FlowControlMixin._maybe_pause_protocol() method contains a defensive
exception handling path when calling protocol.pause_writing():

try:
    self._protocol.pause_writing()
except (SystemExit, KeyboardInterrupt):
    raise
except BaseException as exc:
    self._loop.call_exception_handler({
        'message': 'protocol.pause_writing() failed',
        'exception': exc,
        'transport': self,
        'protocol': self._protocol,
    })

Current situation

While normal flow-control behavior is covered by existing tests, the exception
handling branch (when pause_writing() raises an error) is not explicitly
tested.

Proposed test coverage

This issue proposes adding a unit test to ensure that:

  • protocol.pause_writing() is called when write buffer exceeds high-water mark

  • If pause_writing() raises an exception:

    • loop.call_exception_handler() is invoked
    • The exception object is correctly passed to the handler
    • The error message contains "protocol.pause_writing() failed"
    • The transport remains in _protocol_paused = True state

Why this matters

This behavior is part of asyncio’s flow control robustness and ensures that
protocol-level errors do not silently break transport state transitions.
Explicit testing prevents regressions in error-handling logic inside
_FlowControlMixin.

Linked PRs

Activity

  1. added
    tests
    stdlib
    on May 24, 2026
  2. added a commit that references this issue on Jul 24, 2026
  3. moved this from Todo to Done in asyncioon Jul 24, 2026
  4. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibteststopic-asyncio

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions