Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix microsoft#303: Error message if subprocess exits before attach to…
Browse files Browse the repository at this point in the history
… it completes

When "subProcessId" is specified, but there's no matching subprocess, pretend that attach succeeded, but immediately terminate the session afterward.
int19h committed Jun 25, 2020

Verified

This commit was signed with the committer’s verified signature.
stmcginnis Sean McGinnis
1 parent e8bd6c1 commit b573352
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/debugpy/adapter/clients.py
Original file line number Diff line number Diff line change
@@ -185,6 +185,8 @@ def handle(self, request):
)

f(self, request)
if request.response is not None:
return

if self.server:
self.server.initialize(self._initialize_request)
@@ -449,13 +451,20 @@ def attach_request(self, request):
self.channel.send_event("debugpyWaitingForServer", {"host": host, "port": port})
conn = servers.wait_for_connection(self.session, pred, timeout)
if conn is None:
if sub_pid != ():
# If we can't find a matching subprocess, it's not always an error -
# it might have already exited, or didn't even get a chance to connect.
# To prevent the client from complaining, pretend that the "attach"
# request was successful, but that the session terminated immediately.
request.respond({})
self.session.finalize(fmt('No known subprocess with "subProcessId":{0}', sub_pid))
return

raise request.cant_handle(
(
"Timed out waiting for debug server to connect."
if timeout
else "There is no debug server connected to this adapter."
if sub_pid == ()
else 'No known subprocess with "subProcessId":{0}'
),
sub_pid,
)

0 comments on commit b573352

Please sign in to comment.