Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report sockets opened by debugpy #1337

Closed
paulacamargo25 opened this issue Jul 27, 2023 · 3 comments
Closed

Report sockets opened by debugpy #1337

paulacamargo25 opened this issue Jul 27, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request P1

Comments

@paulacamargo25
Copy link

In order to implement the Port Attributes API. We need to know the port info that debugpy generates for the debugging process. You can send this as a log message that we can track and then disable port forwarding on those ports.

@int19h int19h added the enhancement New feature or request label Sep 12, 2023
@int19h int19h self-assigned this Sep 12, 2023
@int19h int19h added the P1 label Sep 28, 2023
@int19h int19h changed the title Get port info from debugpy Report sockets opened by debugpy Oct 3, 2023
int19h pushed a commit to int19h/debugpy that referenced this issue Oct 3, 2023
Send "debugpySockets" event with information about opened sockets when clients connect and whenever ports get opened or closed.
int19h pushed a commit to int19h/debugpy that referenced this issue Oct 3, 2023
Send "debugpySockets" event with information about opened sockets when clients connect and whenever ports get opened or closed.
@int19h
Copy link
Contributor

int19h commented Oct 3, 2023

@paulacamargo25
The protocol is as follows: when client connects to the adapter, unless it is a secondary session (i.e. subprocess attach), it receives a debugpySockets event looking something like this:

        {
              "seq": 6,
              "type": "event",
              "event": "debugpySockets",
              "body": {
                  "sockets": [
                      {
                          "host": "127.0.0.1",
                          "port": 63435,
                          "internal": false
                      },
                      {
                          "host": "127.0.0.1",
                          "port": 63437,
                          "internal": true
                      },
                      {
                          "host": "127.0.0.1",
                          "port": 63436,
                          "internal": true
                      }
                  ]
              }
          }

Thereafter, such events are sent whenever the adapter opens or closes a port, with the content of "sockets" updated accordingly. At any given moment, the only ports that should be forwarded are those that were present in the most recent such event with ["internal"] === false.

See #1404 for implementation.

int19h pushed a commit to int19h/debugpy that referenced this issue Oct 3, 2023
Send "debugpySockets" event with information about opened sockets when clients connect and whenever ports get opened or closed.
@int19h int19h closed this as completed in ef9a67f Oct 6, 2023
int19h pushed a commit that referenced this issue Dec 12, 2023
Send "debugpySockets" event with information about opened sockets when clients connect and whenever ports get opened or closed.
int19h pushed a commit to int19h/debugpy that referenced this issue Dec 15, 2023
Send "debugpySockets" event with information about opened sockets when clients connect and whenever ports get opened or closed.
@Anthony-Eid
Copy link

Hi I'm trying to implement a client side debug adapter and I'm having trouble handling debugpySockets event. Is it safe to ignore the event? And when you mention port forwarding do you mean that the client should also listen to ports marked with ["internal"] = false when running a debugger?

Thanks in advance!!

@int19h
Copy link
Contributor

int19h commented Jul 19, 2024

It is safe to ignore that event; it is there in case you need that information. This applies more broadly to any custom debugpy events, since if it required special processing by the client, it would mean that clients that only speak standard DAP couldn't use it.

"Forwarding" in the discussion above specifically pertains to VSCode port forwarding when doing remote debugging (e.g. in Docker containers) - in that case the part of the client that handles that will need to know which ports need to be forwarded from the container to VSCode so that the latter can attach to the debugger inside the container. If you're not doing anything like that you don't have to worry about it.

If you are doing anything like that, the only ports that you need to care about are indeed those that are not "internal" - the ones that are "internal" are used for local IPC between debugpy components and debuggee, basically. The "internal" ones are there in case you need to know whether a port being opened is owned by debugpy regardless of how it is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1
Projects
None yet
Development

No branches or pull requests

3 participants