Ensure Debugpy closes connection after a disconnect response #1859
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.
Until now, the process of closing the connection between Debugpy and a client (e.g. VSCode) would be the following:
The problem is that, unlike VSCode, not all clients send this empty line. Because of that, when a user shuts down the debugger, the Debugpy's process won't die. It keeps waiting for that empty line to close the connection and at the same time occupying the communication port with the client. I believe this is the reason for the bug reported in #1783.
AFAIK, sending an empty line is not a part of the DAP protocol. Therefore, Debugpy shouldn't rely on it and should instead proactively close connection once it sends a disconnect response to the client.
This PR aims to fix this.