vscode-go
vscode-go copied to clipboard
debug: debugging session terminates before the debugee finishes its exit job
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?
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.
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.
@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
@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.
@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 .
Good to hear that console
attribute with "integratedTerminal" or "externalTerminal" helps this.
Closing.
@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 https://github.com/golang/vscode-go/issues/120 (even though the original issue was open when we were using legacy debug adapter).

it doesn't work for me with the setting in screenshot, getting error layer=dap runtime error: EOF
any advice?
Thanks
![]()
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?
yeah, i always got the error