Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

PTVSD needs to wait for a little while before closing the socket after sending the last message #530

Closed

Description

Environment data

  • PTVSD version: Master
  • OS and version: Mac
  • Python version (& distribution if applicable, e.g. Anaconda): N/A
  • Using VS Code or Visual Studio: VSC

Related to VSC issue microsoft/vscode-python#2064

Actual behavior

  • PTVSD shuts down even before VSC receives the entire packet

Expected behavior

PTVSD Should wait for some random time waiting for VSC to receive the message before terminating the socket.

Possible solutions

Note: VSC has a slight delay of 100ms for such situations (e.g. if PTVSD dies, or user kills the PTVSD process manually, etc). In such cases VSC sends the terminated event.

Solution 1: We could do the same here, if disconnect request is received with a restart flag, PTVSD can wait for 100ms before killing the socket.
Solution2:

  • First send the response, then invoke notify_disconnecting
  • This seems to work. Would prefer to still add the delay based on the restart flag in the disconnect request. A delay of 100ms.
        self.send_response(request)
        self._notify_disconnecting()
        self._set_disconnected()

/c Eric Snow (@ericsnowcurrently)

Steps to reproduce:

  1. Start debugging
  2. Add a breakpoint
  3. Click the Restart button in VSC
  4. PTVSD receives the disconnect request
  5. PTVSD sends the response and immediately disconnects

Activity

  1. DonJayamanne commented on Jun 27, 2018

    @DonJayamanne
    ContributorAuthor
  2. karthiknadig commented on Jun 27, 2018

    @karthiknadig
    Member

    For solution 2 is it a custom message? If so then this won't work for VS.

  3. DonJayamanne commented on Jun 27, 2018

    @DonJayamanne
    ContributorAuthor

    For solution 2 is it a custom message? If so then this won't work for VS.

    Not following you. How should this effect VS. Unless VS also passes the restart flag in the disconnect request. Besides, this is merely a delay of 100ms. I.e. if anything, VS will only see a delay.

    So, this issue will not fix nor break anything in VS. This issue is for VSC only.

  4. karthiknadig commented on Jun 27, 2018

    @karthiknadig
    Member

    No. It does not. I have to check with the Adapter Host folks about this.

    1> [DebugAdapter] --> C (disconnect-19): {"command":"disconnect","arguments":{"terminateDebuggee":true},"seq":19,"type":"request"}
    

    On restart, they terminate the debuggee (see above message) and start another session.

  5. ericsnowcurrently commented on Jun 27, 2018

    @ericsnowcurrently
    Contributor

    FWIW, I've landed a few PRs that improve the situation. Apparently they do not quite solve the problem yet, though. Per Don, the sys.exit() call blocks indefinitely. I have not seen this issue in our tests, but who knows.

  6. DonJayamanne commented on Jun 29, 2018

    @DonJayamanne
    ContributorAuthor

    Eric Snow (@ericsnowcurrently) I've created some tests for this in #539 (currently disabled and incomplete).

  7. 8 remaining items

  8. DonJayamanne commented on Aug 2, 2018

    @DonJayamanne
    ContributorAuthor

    I found the cause and a managed to hack a work around

    Time to clean up the hack.

  9. karthiknadig commented on Aug 18, 2019

    @karthiknadig
    Member

    The out-of-proc debug adapter handles cleanly shutting down debuggee process and issues the relevant messages in case the debuggee is killed by user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions