Skip to content

Fix Python bug in async mode#1926

Merged
texodus merged 2 commits intomasterfrom
python-loop-bug
Jul 30, 2022
Merged

Fix Python bug in async mode#1926
texodus merged 2 commits intomasterfrom
python-loop-bug

Conversation

@texodus
Copy link
Member

@texodus texodus commented Jul 30, 2022

Fixes a bug introduced in #1828. Handler callbacks need to dispatch to the event loop from the framework in order to re-inject responses after PerspectiveManager is invoked, and this loop is captured by the top-level invoking thread via get_event_loop() (in this refactor). However, due to a closure misapplication, this loop was exclusively being captured from the Perspective thread instead.

The impact of this can be seen in the python-tornado-streaming example within a few seconds of a client connecting, or in the trio of tests this PR adds.

ERROR:asyncio:Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
  File "~/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "~/python3.9/site-packages/tornado/platform/asyncio.py", line 189, in _handle_events
    handler_func(fileobj, events)
  File "~/python3.9/site-packages/tornado/iostream.py", line 700, in _handle_events
    self._handle_write()
  File "~/python3.9/site-packages/tornado/iostream.py", line 974, in _handle_write
    self._write_buffer.advance(num_bytes)
  File "~/python3.9/site-packages/tornado/iostream.py", line 183, in advance
    assert 0 < size <= self._size
AssertionError

@texodus texodus added bug Concrete, reproducible bugs and removed cla-present labels Jul 30, 2022
@texodus texodus merged commit f356625 into master Jul 30, 2022
@texodus texodus deleted the python-loop-bug branch July 30, 2022 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Concrete, reproducible bugs

Development

Successfully merging this pull request may close these issues.

1 participant