Skip to content

Repeated debugpy.listen() calls should be an error #460

Open

Description

Environment data

  • debugpy version: 1.1.0
  • OS and version: Linux 5.4.60-gentoo-x86_64
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.6 from Miniconda
  • Using VS Code or Visual Studio: No

Actual behavior

A "disconnect" request does not seem to really terminate the debug adapter as stated here. It looks like the adapter is still running in the background and that you can reconnect with "initialize" request.

Expected behavior

After a "disconnect" request, the debug adapter should be restarted the same way it was started the first time.

Steps to reproduce:

  1. Execute the following python code in the debugee
import debugpy
debugpy.listen(5416);
  1. Send "initiliaze" and "attach" requests.
  2. After receiving an attach response, send a "disconnect request";
  3. Repeat step 1. debugpy.listen never returns.

If I skip step 4 and repeat step 2 after step 3, everything works fine but this does not seem to be conformant with the DAP specification.

Activity

  1. int19h commented on Nov 3, 2020

    @int19h
    Contributor

    listen() is not supposed to be called multiple times. It starts a debug server in your process, and it's a one-off operation. The server should handle new connections (only one at a time) for as long as the process is running, though.

    That said, "disconnect" request indeed doesn't terminate the adapter, and that's by design. The adapter is necessary for the debug server; and the server, once started, cannot be fully excised from the process for various reasons. The intent of the "disconnect" request, in any case, is to signal to the adapter that debugging should be stopped. It handles that accordingly, by disabling tracing (breakpoints etc) as much as Python implementation details allow.

  2. JohanMabille commented on Nov 3, 2020

    @JohanMabille
    Author

    Thanks for the quick answer!

    I was surprised by this behavior because of the specification of the DAP and its difference with PTVSD, but this seems a reasonable behavior anyway. Do you think it could be worth adding a comment about this difference in this wiki page? I would be glad to do it myself, but I cannot open a PR on a wiki page.

  3. int19h commented on Nov 3, 2020

    @int19h
    Contributor

    It should be https://github.com/microsoft/debugpy/wiki/API-Reference - I've added a clarification on listen() there.

    However, I think there's a separate issue here. You mentioned that on step 4, the second call to listen() never returns at all. Normally, I would expect it to complain that the port is already open and cannot be re-used. That said, it's possible to call listen() with another port, too, and we don't try to check for that right now. A check with a clear error message here would improve this scenario a lot.

  4. fabioz commented on Nov 5, 2020

    @fabioz
    Collaborator

    Hanging in a 2nd listen() call does actually seem like a bug to me.

  5. int19h commented on Nov 5, 2020

    @int19h
    Contributor

    Yes, that part is definitely a bug, hence why this remains open. But I'd like to know why it didn't fail because the port is already opened - it does that when I try to repro. And if I specify a different port, then it apparently succeeds (but should fail loudly).

  6. added this to the Dev 17.x milestone on Oct 20, 2021
  7. heartacker commented on Jun 7, 2022

    @heartacker

    #870 (comment)

    maybe this is a good solution for this situation

  8. changed the title [-]Cannot Attach again after disconnect[/-] [+]Repeated debugpy.listen() calls should be an error[/+] on Feb 1, 2023
  9. heartacker commented on Jun 5, 2023

    @heartacker

    anyupdates? we need this indeed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions