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

vscode: remote-debug: Preventively kill gdbserver #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tksc
Copy link

@tksc tksc commented May 4, 2022

An existing gdbserver process prevents the vscode debug session. So
kill all running gdbserver beforehand.

An existing gdbserver process prevents the vscode debug session.  So
kill all running gdbserver beforehand.
@michaelolbrich
Copy link
Member

Hmm, so we have two somewhat related issues:

  1. sometimes a gdbserver process is not stopped
  2. two gdbserver try to use the same port

I assume, that the second is what's visible here right? The new gdbserver tries to bind to a port and that fails.
And calling kill here like this is racy: it asynchronous, so the new gdbserver may try to bind the port before it is release.

Maybe randomize the port for this:

LOCAL_PORT="$((($$%10000)+10000))"
...
 ssh -L"${GDBSERVER_TARGET_PORT}:localhost:${LOCAL_PORT}" "${GDBSERVER_USER_REMOTE}@${GDBSERVER_TARGET_HOST}" << EOF
...
 gdbserver --once :"${LOCAL_PORT}" "${GDBSERVER_EXECUTABLE}"

This also helps with other conflicting ports: and if one try fails, then the next one will succeed.

I'm not so sure about remaining gdbserver processes. Why do they stick around anyways? I assume the ssh connection was terminated? Or are you accidentally reusing the port forwarding from the old one?

@tksc
Copy link
Author

tksc commented May 5, 2022

IIUC (the error message), your assumption on the double port usage is right.

Failed to attach: Remote communication error. Target disconnected.: Connection reset by peer. (from target-select remote :14242)

Randomizing the port will be a good thing either way.

Or are you accidentally reusing the port forwarding from the old one?

I just use Start, Stop and Restart from VSCode.

I will investigate this behavior further. Right now I cannot reproduce it in a consistent way.

@michaelolbrich
Copy link
Member

I think, the ssh process remains as well. We just start the task in the background, so if gdbserver sticks aground, then ssh will as well.

These is a "postDebugTask" that we could use, see for example:
microsoft/vscode#90786
https://stackoverflow.com/questions/54480792/terminate-another-task-from-within-a-postdebugtask-vs-code

That would probably mean stopping all tasks, but I think that's ok. I don't see an API that allows us to stop a specific task.

Then the ssh should be gone at least. I'm not so sure about the gdbserver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants