Repository navigation
Description
main's push run for 06d547f3 (run 46226544729, first attempt) failed in one file, tests/adapters/python/integration/python-attach-close-busy-target.test.ts, on Ubuntu. Both of its tests failed the same way, at the same step.
What happened
Each test attaches to a target started with python -m debugpy --listen, makes the target hold the interpreter, ends the session (a close in one test, a detach joined by a close in the other), lets the target go, and then checks that the same port serves a new attach (portServesANewAttach).
Everything up to that last step passed in both tests: the ending answered released: true with no warning, the hold ended by the test's own byte, and the target process was alive. Then the new attach was refused:
Failed to attach: Critical initialization error: Failed to connect DAP client: nothing accepted a connection on 127.0.0.1:33229 within 12.5s (12.5s elapsed, 61 attempts; last error: connect ECONNREFUSED 127.0.0.1:33229) [direct connect to 127.0.0.1:33229; no adapter process was started]
Refused, 61 times over 12.5 s, means nothing was listening: the target's debug adapter had gone, although the server had been told the release was answered. That is the outcome #1325 exists to prevent, reached by a route its repair does not cover.
What is known
- It is not deterministic. The same tree passed this file in the pull request's own run 25 minutes earlier (fix(python): a logpoint's message is checked by the program's own interpreter before it is sent #1371, Ubuntu and Windows), and in four runs on a two-core Ubuntu machine during that change. After the failure: the file alone, on that two-core machine, passed 15 of 15 at the merged tree and 15 of 15 at the commit before the merge. Before the merge,
main's last eleven push runs were green. So the failure needs something a full run has and the file alone does not (load, or another test file running beside it), and one failure cannot say whether the merge made it more likely. - The merged change (fix(python): a logpoint's message is checked by the program's own interpreter before it is sent #1371) does not touch an attach's close, except for one awaited call after the proxy has stopped that returns at once when the session has no logpoint checker, which an attach never has. I could not derive a route from it to this failure, and I could not rule one out without the adapter's own log.
- debugpy's adapter ends itself on any exception in a message handler or while finalizing a session (
debugpy/common/messaging.py,_run_handlers:self.close(); os._exit(1);debugpy/adapter/sessions.py,finalize:os._exit(1)). The known trigger is a client that closes its connection before a reply is written. Here the reply todisconnectwas received, so it was something after it. - Both tests failing in one run points at something common to that run (the machine's speed at that moment, or the one server process the file's tests share) rather than two independent accidents.
What cannot be answered from this run
Why the adapter went. Neither the test nor CI keeps the two logs that say:
- the adapter's own log (
debugpy --log-to <dir>on the target's command line writes it, and the adapter logs the exception before it exits); - the server's per-session proxy log, whose path is in the error (
tests/adapters/sessions/<id>/run-…/proxy-<id>.log) and which is gone with the runner.
Expected
- The test starts its target with
--log-tointo its scratch directory and, when the new attach is refused, puts the tail of the adapter's log into the assertion's message. The next occurrence then names its own cause. - CI uploads the session logs of a failed integration job as an artifact (an upload step with
if: failure()), so a failure of any attach test can be read after the fact. - With the cause known: either a route in our teardown that still lets the adapter meet a closed connection (then it is a defect of ours, in the class of javascript: a connection to a Node target is closed while it may still be writing, in thirteen places (the class behind #1119) #1373), or a race inside debugpy (then it joins the upstream queue, with a fix).
Class: a failure that cannot be diagnosed from its own record. Path: edge (a session ended on a busy attached target), but the cost when it happens outside a test is the user's process losing its debug port for good.
Activity
debugmcpdev commentedon Nov 29, 2026
A lead, from debugpy's own log on a run that was made to fail on purpose (#1377 adds the log keeping; debugpy 1.8.20, Windows). It is not yet the log of a real failure.
After the
disconnecthad been answered and the client had gone, the adapter logged:So the debuggee goes on sending events after the client has left, and the adapter's handler for them meets a client that is gone. In that run the error was the kind debugpy logs and survives. For any other exception in a handler it closes and exits (
debugpy/common/messaging.py,_run_handlers), which would close the port exactly as seen.What that suggests, to be checked against a real failure's log:
disconnecthas been answered, let the adapter close the connection and wait for that under a bound, instead of closing first. That is the same class as javascript: a connection to a Node target is closed while it may still be writing, in thirteen places (the class behind #1119) #1373, from the other side.Nothing is changed in the server on this lead alone.
debugmcpdev commentedon Nov 29, 2026
The re-run of the failed jobs passed on both systems (run 46226544729, attempt 2, same commit), so
mainis green again. One failure in two full runs at this commit; 30 of 30 passes for the file alone.test(python): a refused attach in the busy-target test says why; CI k…
debugmcpdev commentedon Nov 29, 2026
The log-keeping merged as #1377 is now proven on both systems, by a probe that failed this test on purpose (#1379, closed unmerged): on each system the two artifacts arrive and hold debugpy's adapter, server and pydevd logs for both targets, and the failure's message carries both log tails.
Two things the probe showed besides:
fail-fast, so when one system's test job fails, the other's is cancelled where it stands. In the run that failed onmain(46226544729, attempt 1) the Linux job failed at 05:13:26 and the Windows job was cancelled ten seconds later, so that run never said whether the test fails on Windows too.fail-fast: falseon that matrix would let the other job finish, at the cost of runner minutes on red runs only.All debug servers disconnected; waiting for remaining sessions...andAll debug sessions have ended; exiting., well under a second after the second session connected: that is the test ending its target. None of the four holds acouldn't handleline, adisconnected unexpectedlyline or a traceback. So the adapter also leaves by design when its debug server's connection ends, and that is a second thing to look for in a real failure's log, beside an exception in a handler.debugmcpdev commentedon Nov 29, 2026
Tried to reproduce it in the shape it failed in: CI's own test command (
vitest run --coverage --project unit --project integration) three times in a row on a two-core Ubuntu machine atfa41bf26. All three runs passed (534 files each), this file among them. So it stands at one failure in the full job on a runner, none in three full runs and thirty runs of the file alone elsewhere. The next occurrence in CI will carry its logs.debugmcpdev commentedon Nov 29, 2026
Reproduced locally with the debugpy adapter log that #1377 makes the test keep. This is the first capture that says why.
What failed:
python-attach-close-busy-target.test.ts, "keeps the target's debug port when the session is closed while the target holds the interpreter". The second attach answerednothing accepted a connection on 127.0.0.1:<port> within 12.5s ... ECONNREFUSED.What the target's adapter log shows (times are seconds since the adapter started):
The adapter finished handling the
disconnectat +4.971 s (session finalized, client stream closed) and failed to send its answer 60 ms later withNoMoreMessages: the client's side of the connection was already gone. So the server's wait for thedisconnectanswer ended before the busy target let the adapter answer. The adapter treated that as the client leaving first and exited, taking the port with it. That is the mechanism of #1325 again, reached when the target's busy period and our wait end at about the same moment.Conditions: Windows 11, Python 3.13.12, debugpy 1.8.20, mains power, the machine loaded by other test runs at the time. The branch under test changes the Python launch path only; this test attaches to a target it starts itself.
So the flake is a real margin: the close's bound against how long the target holds the interpreter. Under load the two meet.