Repository navigation
Warn instead of exiting when the adapter endpoints file can't be written - #2109
Open
om singhal (Om-singhaI) wants to merge 1 commit into
Open
om singhal (Om-singhaI) wants to merge 1 commit into
om singhal (Om-singhaI) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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.
Fixes #1866
When
DEBUGPY_ADAPTER_ENDPOINTSnames a file that can't be written, for example a path a terminal kept from an earlier VS Code session whose directory is gone, the adapter thatdebugpy.listen()spawns sends its endpoints to the debug server, then fails to write the file and exits. Its stdio is already closed by then, so the real error never reaches the user (on Python 3.12 and later the terminal only shows a barelost sys.stderrdump):listen()returns normally, but nothing is listening on the port and the client's connection is refused.Following the discussion in microsoft/vscode-python-debugger#612, where a warning was suggested instead of a crash, this makes the failure a warning on that path:
src/debugpy/adapter/__main__.py: with--for-server, the endpoints file is written just before the endpoints are sent to the debug server instead of just after. If writing it fails, the adapter logs a warning, keeps running, and adds a"warning"entry to the endpoints it sends. Without--for-servera failure is still fatal, since there the file can be the only way to learn the port. If sending the endpoints fails, the listeners are now closed before exiting, so the file is still deleted only after the ports are closed.src/debugpy/server/api.py: a"warning"in the endpoints is logged, so it shows on the debuggee's stderr with the defaultDEBUGPY_LOG_STDERR. It's the only new stderr output, and only when the variable is set and the write failed.tests/debugpy/test_attach.py:test_attach_api_endpoints_file_not_writablepoints the variable at a missing directory, callsdebugpy.listen(), attaches, stops at a breakpoint, and checks the warning on stderr.Writing the file a little earlier means a client watching it can connect a moment before the debug server does, which could already happen on
mainsince the debug server connects back only after it gets the endpoints. An attach with"connect"waits up toPROCESS_SPAWN_TIMEOUTfor the server in that case (clients.py).Testing on macOS with CPython 3.13 and
PYTHONPATH=src:src/restored frommainit fails withConnectionRefusedError, the error from the issue.tests/debugpy/test_attach.py,test_api.py,adapter/,server/andtest_run.py: 332 passed, 45 skipped. I left out the PID attach cases andtest_nodebug, whose cases crash the pytest worker with no output on this machine, the same way onmain.--port 0, no--for-serverand a missing directory, it still exits with theFileNotFoundErroras onmain.ruff check .passes, and black reports nothing new for the changed lines.