Repository navigation
Pyjo.Server.Daemon: the data of a connection that the daemon has removed, whose stream reads on while it closes gracefully, is discarded - #554
Merged
Conversation
…ay be due a millisecond early Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ved, whose stream reads on while it closes gracefully, is discarded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Tests
|
dex4er
added a commit
to pyjoyment/Pyjo-Reactor-Winloop
that referenced
this pull request
Nov 5, 2026
Pyjoyment of Git main with pyjoyment/Pyjoyment#553, a sleep of Pyjo.Steps in its tests on an event loop of libuv, whose timer may be due a millisecond early, and pyjoyment/Pyjoyment#554, the data of a connection that the daemon has removed discarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 of 5 tasks
dex4er
added a commit
to pyjoyment/Pyjo-Reactor-Winloop
that referenced
this pull request
Nov 5, 2026
…ime, and a timer not due before its time (#6) * Pyjo.Reactor.Winloop: a socket that loops watch, polled by one at a time libuv of Windows polls a socket with an exclusive request of AFD, which ends the request of any other loop for the same socket, also of a copy of it, and that loop polls it again, in a busy loop of C with no event at all. The workers of Pyjo.Server.Prethread watch the listen sockets of the manager on Windows, the same sockets in every thread: four idle loops took 240% of the processors and starved the process and the tests next to it, with or without the GIL. _Loop keeps the readers and the writers of each socket, and a registry of the process has the loops that watch it, the owner that libuv polls it for, and the loops that run and wait for it. The owner hands it over to the next one after each of its events, so that the connections go to every worker in turn, and at the end of its run; a loop changes the polls of libuv only in its thread. A socket that one loop watches goes to libuv as before. Closes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * uv.lock: Pyjoyment of Git main at 1fc984a Pyjoyment of Git main with pyjoyment/Pyjoyment#550 and pyjoyment/Pyjoyment#552, the tests of a page of GitHub without its title in the tutorial and of the servers of Hot and Reload that did not answer or did not stop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * uv.lock: Pyjoyment of Git main at 7b09754 Pyjoyment of Git main with pyjoyment/Pyjoyment#553, a sleep of Pyjo.Steps in its tests on an event loop of libuv, whose timer may be due a millisecond early, and pyjoyment/Pyjoyment#554, the data of a connection that the daemon has removed discarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Pyjo.Reactor.Winloop: a timer not due before its time libuv counts a timer in whole milliseconds from uv_now, its clock rounded down, and Winloop rounds the delay to them, as uvloop does, so a timer, as asyncio.sleep, was due up to a millisecond before its time, where the loop of asyncio is never early: a sleep of 2 ms took 1.5 ms. call_later of _Loop, which call_at of Winloop calls too, rounds the delay up to a millisecond and adds the one that the clock loses, as _Loop of Pyjo.Reactor.Uvloop does, after MagicStack/uvloop#755. The subtest of Pyjo-Reactor-Uvloop measures with time.perf_counter, which time.monotonic is on Windows since Python 3.13, and which counted in the ticks of the system of 15.6 ms before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Pyjo.Reactor.Poll.Pyjo_Reactor_Poll: I/O watcher failed: '<id>' at Pyjo/Server/Daemon.py line 918on the standard error oft/Pyjo/App_ASGI.py, which passed, inprove (python pypy3.12, Poll)of #553 (job):_readof the daemon got the data of a connection that it had removed already, andself._connections[id]raisedKeyError.Why
The daemon removes the connection of a WebSocket in
_finish, which the callback of the eventdrainof its last write calls.removeof the event loop closes the stream gracefully, and the stream was still writing then, with an empty buffer, as the callback of another write, which came during the emit ofdrain, waited for the next one. So the stream read on until its next writable event, while the daemon had dropped the connection at once, and a pong of the client that came first was read for a connection that was gone. Mojo makes the connection again there, as Perl autovivifies it, and builds a transaction of the data; the other handlers of the daemon,_write,_finishand_trace, take a connection that is gone already.Reproduced with
t/Pyjo/App_ASGI.pyon PyPy 3.12 andPyjo.Reactor.Pollin a container of Linux on arm64, once in 40 to 120 runs, with the stacks of the removal and of the read recorded.Changes
Pyjo.Server.Daemon:_readdiscards the data of a connection that the daemon has removed, with an# Unlike Mojolicious:marker.t/stdlib/Server_Daemon.py:Data of a connection that the daemon has removed, a response withConnection: closewhose stream is kept writing, as by another callback ofdrain, until the client has sent data after the response; it fails without the change with the error of the reactor of CI.Validation
Pyjo.Reactor.PollPYTHONDEVMODE=1on the asyncio reactor and onPyjo.Reactor.Pollt/Pyjo/App_ASGI.pyon PyPy 3.12 withPyjo.Reactor.Pollin the container, without the error, where it came once in 40 and once in 120 beforetrunk check🤖 Generated with Claude Code