Repository navigation
pycvc.ariadne's tests keep the tasks they start, so a garbage collection mid-request loses none - #1243
Merged
Conversation
…ion mid-request loses none On Windows, pycvc_ariadne_server hung until its timeout on every run from #1168 on, with "Task was destroyed but it is pending!" for its client() task. It was not Windows, Winsock or asyncio's proactor: it was the garbage collector, and the test. The test started client() with a bare host.loop.create_task(client()) and kept no reference. The loop holds tasks only weakly, and a client of asyncio.open_connection waits on its StreamReader, which its protocol holds only weakly too. So while client() waits for the response, the only references to the task are a cycle of its own: task -> coroutine frame -> reader -> waiter future -> the task's wakeup callback. The first full (generation 2) collection that runs in that wait frees the task. stop(7) never runs, and host.run() waits forever. Whether a full collection falls in that wait is set by how many objects were allocated before it. On a286873 the first one of the run falls 30 ms into the wait. #1168 is the commit that moves it there: its input-trace wrappers (pycvc_trace.i) leave about 400 more objects at import pycvc (30,264 -> 30,664). On its parent, 8857fe8, no full collection runs before the test ends, so it passed. The bug was there before: a gc.collect() while client() waits hangs 8857fe8 the same way. A minimal asyncio program with no pycvc (start_server, a client task nothing holds, one gc.collect() in the handler) loses its client the same way on Linux's selector loop and on Windows' proactor. And padding the unchanged test with 1,500 extra objects before import pycvc makes it pass on a286873 again. The other clues fit as well: runpy.run_path, and a sitecustomize without the importlib imports, each allocate a different number of objects. The fix: the test keeps client_task. Its /ping handler now runs gc.collect(), so a full collection always falls in the request and the test checks that every task on the loop survives one, the host's and its own. Before this fix that hangs on every platform, not only where the counts happen to land in the wait. arisrvx's own path was already safe: _Program.spawn, _Served.task and uvicorn's per-connection tasks are all held. The arisrv ctest programs used the same unheld idiom. http_listen.py's selftest waits on a stream exactly as client() did, and so do service.py's selftest and its /slow request. Each now keeps its tasks, and http_listen.py's /ping runs gc.collect() too, so arisrvx_http_listen checks the arisrvx side under a full collection. program.py (arisrvx_program, the arisrvx package's smoke test) waits on asyncio.sleep, whose timer keeps the task alive; it keeps its task as well, as an example to copy. The module docstring and ARIADNE.md's script-thread bullet now say to keep the task host.loop.create_task() returns: a service that starts one without keeping it, and waits on a stream of its own, loses it the same way on any platform.
transfix
enabled auto-merge (squash)
November 14, 2026 22:08
transfix
added a commit
that referenced
this pull request
Nov 15, 2026
- app_runtime.cpp: the constructor hands the scene its repeat: count function (#1230), then takes the verb table's lock as before. - e2ee_intrinsics.cpp (#1191): the e2ee-* provider registers its async functions on the calling program's host (*ictx.host, else the app's), as every provider on this branch does (B30), so an isolated document's e2ee-backup and e2ee-restore park on its own group. - STATE_EXEC_THREADED.md: the e2ee provider in the provider table and the file list.
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.
On Windows,
pycvc_ariadne_server(bindings/pycvc/test_pycvc_ariadne_server.py) hung until its timeout on every run from #1168 on. Each run printedTask was destroyed but it is pending!for itsclient()task. Windows, Winsock, asyncio's proactor and the GIL had nothing to do with it. The garbage collector freed a task that the test never kept.Cause
The test started its HTTP client with a bare
host.loop.create_task(client())and kept no reference to the task.asyncio.open_connectionwaits on itsStreamReader, and its protocol holds that reader only weakly too.So while
client()waits onawait reader.read(), the only references to the task are a cycle of its own:The first full (generation-2) collection that runs during that wait frees the task.
host.stop(7)never runs, andhost.run()waits forever.Whether a full collection lands in that wait depends on how many objects were allocated before it. That is why the hang moved with unrelated changes.
import pycvcgens run: [95, 8, 0])import pycvcgc.disable()at the topThe other clues from the report fit the same way.
runpy.run_path, and a sitecustomize without theimportlibimports, each allocate a different number of objects before the test runs.Bisect
#1168 is the commit that turns it on, but it is not the bug. Its input-trace wrappers (
pycvc_trace.i) leave about 400 more objects atimport pycvc, and that moves the run's first full collection into the client's wait.The bug was there before #1168:
gc.collect()whileclient()waits hangs the 8857fe8 build the same way.start_server, a client task nothing holds, onegc.collect()in the handler) loses its client the same way on Linux's_UnixSelectorEventLoop(Python 3.10, WSL) and on Windows'ProactorEventLoop(3.12). Keeping a reference fixes it on both.Linux CI passes only because its allocation counts happen not to put a full collection in that wait.
Fix
test_pycvc_ariadne_server.py: keepsclient_task. Its/pinghandler now runsgc.collect(), so a full collection always falls inside the request. The test now checks that every task on the loop survives one, the host's tasks and its own. On every platform, the old test with that line added hangs.http_listen.py's selftest waits on a stream exactly asclient()did. It now keeps its task, and its/pingrunsgc.collect()too, soarisrvx_http_listenchecks arisrvx's own path under a full collection.service.py(arisrvx_serve): its selftest and its in-flight/slowrequest are kept intasks.program.py(arisrvx_program, and the arisrvx package's smoke test in publish-cvcpkg.yml) waits onasyncio.sleep, whose timer keeps its task alive, so it could not hang this way. It keeps its task anyway, because it is the example people copy.pycvc.ariadnemodule docstring and ARIADNE.md's script-thread bullet now say to keep the taskhost.loop.create_task()returns until it is done.arisrvx's own serving path was already safe:
_Program.spawn,_Served.taskand uvicorn's per-connection tasks are all held. A packaged arisrvx serving HTTP does not hang this way. A service's own code would, on any platform, if it starts a task without keeping it and that task waits on a stream of its own, which is what the docs now warn about.Verification
Windows 11, MSVC 14.44, static Release (pycvc core on, pycvc_gl off), Python 3.12.10. Built at this branch (master 4239741 + this commit):
pycvc_ariadne_server, this branch's testTask was destroyed but it is pending!)/pinggc.collect()(task not kept)arisrvx --python http_listen.py --http-listen …, this branch's programTask was destroyed, no selftest line)-R '^(arisrvx_|pycvc_ariadne)'Linux has not been run here beyond the minimal asyncio repro. pycvc-linux and the arisrvx lanes on this PR are the check there.