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

debug: debugging session terminates before the debugee finishes its exit job #2137

Open
ztibeike opened this issue Mar 25, 2022 · 10 comments
Open
Labels
Debug Issues related to the debugging functionality of the extension. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@ztibeike
Copy link

I want to capture the OS signal and do some exit jobs when I terminate the vscode golang debugger.

I have code as below:

sigalChan := make(chan os.Signal, 1)
signal.Notify(sigalChan, syscall.SIGINT, syscall.SIGTERM)
<-sigalChan
doSomeJobs()

but it doesn't work. Anyone can tell me how to figure it out? Maybe the signal type is not SIGINT or SIGTERM?

@gopherbot gopherbot added this to the Untriaged milestone Mar 25, 2022
@findleyr findleyr added the Question This is a question, rather than an issue report. label Mar 25, 2022
@findleyr
Copy link
Member

I see you also asked at https://stackoverflow.com/questions/71602708/what-os-signal-does-the-vscode-go-debugger-send-to-delve-dap-when-i-terminate-de, and I suspect that the advice there is accurate.

@polinasok or @suzmue might know if it is possible to catch the debugger exit.

@ztibeike
Copy link
Author

ztibeike commented Mar 25, 2022

I see you also asked at https://stackoverflow.com/questions/71602708/what-os-signal-does-the-vscode-go-debugger-send-to-delve-dap-when-i-terminate-de, and I suspect that the advice there is accurate.

@polinasok or @suzmue might know if it is possible to catch the debugger exit.

Yeah I also asked at stackoverflow and got some advice which however actually do not solve my problem. I still want to know if there's any way to figure it out.

@polinasok
Copy link
Contributor

@ztibeike In theory you need to start a headless dlv server in a terminal and connect to it with a client. In that terminal, the debuggee will be foregrounded, so it can receive the signals. It looks like when that happens vscode-go both with legacy and with dlv-dap adapter does the wrong thing. Execution is paused on an error and the rest of the code doesn't get executed. I need to debug a bit more to understand why this happens. In the meantime, you can use dlv terminal client instead:

$ dlv debug hello.go --headless --listen=:54321
API server listening at: [::]:54321
2022-03-25T09:35:09-07:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
debugserver-@(#)PROGRAM:LLDB  PROJECT:lldb-1205.0.27
 for x86_64.
Got a connection, launched process /Users/polina/go/src/hello/__debug_bin (pid = 57085).

...waiting for signal
^C
!!! got signal !!!
$ dlv connect :54321
Type 'help' for list of commands.
(dlv) c
Stopped at: 0x30b3ad0
=>   1:	no source available
Command failed: EOF
(dlv) exit

@findleyr findleyr added the Debug Issues related to the debugging functionality of the extension. label Mar 25, 2022
@ztibeike
Copy link
Author

ztibeike commented Mar 26, 2022

@polinasok Thanks a lot! It works! Instead of manually running "dlv debug ...", I configure a pre-launch-task in tasks.json to start the debug mode of delve server as below.

// tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "start dlv",
      "type": "shell",
      "command": "/root/go/bin/dlv",
      "isBackground": true,
      "args": [
        "debug",
        "${workspaceFolder}/main.go",
        "--headless",
        "--listen=:54321",
        "--check-go-version=false",
        "--api-version=2"
      ]
    }
  ]
}

Then attach to it . I think it's more efficient. But there's still a little problem as you got, I can catch the exit and run the rest of code by pressing "ctrl+c", but can't to do so by clicking the UI button. The error log is:

2022-03-26T14:24:43+08:00 error layer=rpc writing response:write tcp 127.0.0.1:54321->127.0.0.1:40676: use of closed network connection

I think the debugger just shut down it's listening port to close the connection, then delve server crashes, the golang program exit along with the delve.

@ztibeike
Copy link
Author

ztibeike commented Mar 26, 2022

@polinasok Thanks a lot! It works! Instead of manually running "dlv debug ...", I configure a pre-launch-task in tasks.json to start the debug mode of delve server as below.

// tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "start dlv",
      "type": "shell",
      "command": "/root/go/bin/dlv",
      "isBackground": true,
      "args": [
        "debug",
        "${workspaceFolder}/main.go",
        "--headless",
        "--listen=:54321",
        "--check-go-version=false",
        "--api-version=2"
      ]
    }
  ]
}

Then attach to it . I think it's more efficient. But there's still a little problem as you got, I can catch the exit and run the rest of code by pressing "ctrl+c", but can't to do so by clicking the UI button. The error log is:

2022-03-26T14:24:43+08:00 error layer=rpc writing response:write tcp 127.0.0.1:54321->127.0.0.1:40676: use of closed network connection

I think the debugger just shut down it's listening port to close the connection, then delve server crashes, the golang program exit along with the delve.

I've found that such prelaunch task is unnecessary. I can get the same result when I set "request" to "launch" and "console" to "integratedTerminal" in launch.json .

@hyangah
Copy link
Contributor

hyangah commented Mar 30, 2022

Good to hear that console attribute with "integratedTerminal" or "externalTerminal" helps this.
Closing.

@hyangah hyangah closed this as completed Mar 30, 2022
@hyangah
Copy link
Contributor

hyangah commented Apr 1, 2022

@polinasok pointed out the issue is not resolved. We need to investigate what causesdlv dap to terminate before the debugee to complete the exit job.

Seems similar to #120 (even though the original issue was open when we were using legacy debug adapter).

@hyangah hyangah reopened this Apr 1, 2022
@hyangah hyangah added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Question This is a question, rather than an issue report. labels Apr 1, 2022
@hyangah hyangah changed the title How could I do some exit jobs when I terminate the debugger debug: debugging session terminates before the debugee finishes its exit job Apr 1, 2022
@hyangah hyangah modified the milestones: Untriaged, Unplanned, On Deck Apr 1, 2022
@davidxiao
Copy link

davidxiao commented Sep 9, 2022

Screen Shot 2022-09-09 at 5 10 56 pm

it doesn't work for me with the setting in screenshot, getting error layer=dap runtime error: EOF

any advice?

Thanks

@ztibeike
Copy link
Author

ztibeike commented Sep 9, 2022

Screen Shot 2022-09-09 at 5 10 56 pm

it doesn't work for me with the setting in screenshot, getting error layer=dap runtime error: EOF

any advice?

Thanks

My configuration is totally the same as yours and it works. Can you or how do you reproduce the issue?

@davidxiao
Copy link

yeah, i always got the error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Debug Issues related to the debugging functionality of the extension. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants