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

DAP server abruptly disconnecting #3825

Closed
trevorwhitney opened this issue Oct 8, 2024 · 7 comments
Closed

DAP server abruptly disconnecting #3825

trevorwhitney opened this issue Oct 8, 2024 · 7 comments

Comments

@trevorwhitney
Copy link

trevorwhitney commented Oct 8, 2024

  1. What version of Delve are you using (dlv version)? 1.23.1
  2. What version of Go are you using? (go version)? 1.23.2
  3. What operating system and processor architecture are you using? Mac OS 15.0.1
  4. What did you do?
    I tried to run a launch config for a main.go file with args, from neovim, using nvim-dap and nvim-dap-go
  5. What did you expect to see?
    I expected to see the program launch, as it has for years.
  6. What did you see instead?
    The Dap server quit abruptly, nvim-dap logs and dap logs

I don't understand why the DAP server is terminating, or how to get more information to troubleshoot this?

@aarzilli
Copy link
Member

aarzilli commented Oct 8, 2024 via email

@trevorwhitney
Copy link
Author

trevorwhitney commented Oct 9, 2024

It's a server so it should just keep running until killed. I've tried setting breakpoints, and the DAP server still just terminates without ever hitting the breakpoint. Here's the output from that:

[debug-adapter stderr] 2024-10-08T20:07:29-06:00 debug layer=dap DAP connection 1 started

[debug-adapter stderr] 2024-10-08T20:07:29-06:00 debug layer=dap [<- from client]{"seq":1,"type":"request","command":"initialize","arguments":{"clientID":"neovim","clientName":"neovim","adapterID":"nvim-dap","locale":"en_US.UTF-8","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsRunInTerminalRequest":true,"supportsProgressReporting":true,"supportsStartDebuggingRequest":true}}

[debug-adapter stderr] 2024-10-08T20:07:29-06:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":1,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":true,"supportsConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsSetVariable":true,"supportsExceptionInfoRequest":true,"supportsDelayedStackTraceLoading":true,"supportsLogPoints":true,"supportsDisassembleRequest":true,"supportsClipboardContext":true,"supportsSteppingGranularity":true,"supportsInstructionBreakpoints":true}}

[debug-adapter stderr] 2024-10-08T20:07:29-06:00 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"launch","arguments":{"program":"\/Users\/twhitney\/workspace\/loki\/cmd\/loki\/main.go","type":"go","args":["-config.file=\/Users\/twhitney\/workspace\/loki\/cmd\/loki\/loki-local-config.yaml"],"request":"launch","buildFlags":"","name":"Debug (Arguments)"}}

[debug-adapter stderr] 2024-10-08T20:07:29-06:00 debug layer=dap parsed launch config: {
	"mode": "debug",
	"program": "/Users/twhitney/workspace/loki/cmd/loki/main.go",
	"args": [
		"-config.file=/Users/twhitney/workspace/loki/cmd/loki/loki-local-config.yaml"
	],
	"buildFlags": {},
	"backend": "default",
	"stackTraceDepth": 50
}

[debug-adapter stderr] 2024-10-08T20:07:36-06:00 debug layer=dap building from "/Users/twhitney/workspace/loki": [go build -o /Users/twhitney/workspace/loki/__debug_bin2736654371 -gcflags all=-N -l /Users/twhitney/workspace/loki/cmd/loki/main.go]

[debug-adapter stderr] 2024-10-08T20:07:36-06:00 debug layer=dap launching binary '/Users/twhitney/workspace/loki/__debug_bin2736654371' with config: {
	"mode": "debug",
	"program": "/Users/twhitney/workspace/loki/cmd/loki/main.go",
	"args": [
		"-config.file=/Users/twhitney/workspace/loki/cmd/loki/loki-local-config.yaml"
	],
	"cwd": "/Users/twhitney/workspace/loki",
	"buildFlags": {},
	"output": "/Users/twhitney/workspace/loki/__debug_bin2736654371",
	"dlvCwd": "/Users/twhitney/workspace/loki",
	"backend": "default",
	"stackTraceDepth": 50
}
2024-10-08T20:07:36-06:00 info layer=debugger launching process with args: [/Users/twhitney/workspace/loki/__debug_bin2736654371 -config.file=/Users/twhitney/workspace/loki/cmd/loki/loki-local-config.yaml]

[debug-adapter stderr] 2024-10-08T20:07:37-06:00 debug layer=debugger entryPoint 0x104b28000 machoOff 0x100000000

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 warning layer=debugger debug_frame workaround not applied: function internal/abi.(*RegArgs).Dump (at 0x104b29070) covered by 0x104b29070-0x104b29230

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=debugger Adding target 29771 "/Users/twhitney/workspace/loki/__debug_bin2736654371 -config.file=/Users/twhitney/workspace/loki/cmd/loki/loki-local-config.yaml"

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"launch"}

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=dap [<- from client]{"seq":3,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/Users/twhitney/workspace/loki/cmd/loki/main.go"},"breakpoints":[{"line":38}],"lines":[38]}}

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 info layer=debugger created breakpoint: &api.Breakpoint{ID:1, Name:"sourceBp Path=\"/Users/twhitney/workspace/loki/cmd/loki/main.go\"  Line=38 Column=0", Addr:0x1082d9a38, Addrs:[]uint64{0x1082d9a38}, AddrPid:[]int{29771}, File:"/Users/twhitney/workspace/loki/cmd/loki/main.go", Line:38, FunctionName:"main.main", ExprString:"", Cond:"", HitCond:"", HitCondPerG:false, Tracepoint:false, TraceReturn:false, Goroutine:false, Stacktrace:0, Variables:[]string(nil), LoadArgs:(*api.LoadConfig)(nil), LoadLocals:(*api.LoadConfig)(nil), WatchExpr:"", WatchType:0x0, VerboseDescr:[]string(nil), HitCount:map[string]uint64{}, TotalHitCount:0x0, Disabled:false, UserData:interface {}(nil), RootFuncName:"", TraceFollowCalls:0}
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":3,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"id":1,"verified":true,"source":{"name":"main.go","path":"/Users/twhitney/workspace/loki/cmd/loki/main.go"},"line":38}]}}

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=dap [<- from client]{"seq":4,"type":"request","command":"configurationDone"}
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Type 'dlv help' for list of commands.\n"}}
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":4,"success":true,"command":"configurationDone"}

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=debugger continuing
2024-10-08T20:07:38-06:00 debug layer=debugger ContinueOnce
Type 'dlv help' for list of commands.

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}

[debug-adapter stderr] 2024-10-08T20:07:38-06:00 debug layer=dap DAP server stopping...
2024-10-08T20:07:38-06:00 debug layer=dap halting
2024-10-08T20:07:38-06:00 debug layer=dap process not running
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Process 29771 has exited with status 11\n"}}
2024-10-08T20:07:38-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"output","body":{"category":"console","output":"Detaching\n"}}
2024-10-08T20:07:38-06:00 debug layer=debugger detaching
2024-10-08T20:07:38-06:00 debug layer=dap DAP error: read tcp 127.0.0.1:53286->127.0.0.1:53288: use of closed network connection
2024-10-08T20:07:38-06:00 debug layer=dap DAP server stopped

@aarzilli
Copy link
Member

aarzilli commented Oct 9, 2024

Did you try debugging something other than this program? Did you try debugging by calling dlv from the command line? If you run this program outside of the debugger, with all the same options, compiled with -gcflags='all=-N -l' and CGO_CFLAGS set to -g -O0 does it run or does it segfault?

@trevorwhitney
Copy link
Author

Thanks for helping out on this, it's a huge hit to my workflow to not have a working debugger.

Debugging from the command line (not using DAP) seems to work fine:

CGO_FLAGS="-g -O0" dlv --log --log-output debugger --build-flags "-gcflags='all=-N -l'" debug

This produced a binary I was able to run with the same args and it came up fine. I've only ever used DAP with an editor. I tested out debugging in VSCode (which I understand uses delve's DAP protocol as well), and that worked. Is there an easy way to test the DAP functionality from the command line that you know of?

@trevorwhitney
Copy link
Author

I tried running the debugger on a trivial program and it worked

package main

import (
	"fmt"
	"os"
)

func main() {
	name := os.Args[1]
	fmt.Printf("hello %s\n", name)
}

Up to this line, everything is the same. The working program prints [debug-adapter stderr] 2024-10-09T08:51:41-06:00 debug layer=debugger callInjection protocol on when the non-working program prints [debug-adapter stderr] 2024-10-09T08:53:43-06:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"terminated","body":{}}. I'm assuming this is some delve error? Is there any way to figure out why the callInjection protocol is failing?

@aarzilli
Copy link
Member

aarzilli commented Oct 9, 2024

I'm assuming this is some delve error? Is there any way to figure out why the callInjection protocol is failing?

That's irrelevant, it just prints that when it stops at a breakpoint.

This produced a binary I was able to run with the same args and it came up fine

You don't need to manually specify CGO_CFLAGS and -gcflags when calling dlv. What did you do exactly with the debugger called from the command line?

@trevorwhitney
Copy link
Author

@aarzilli thanks again for all your help on this, I think I finally got to the root of it and it doesn't seem to be related to delve.

For anyone else who finds themselves here. The project I was failing to run in the debugger was grafana/loki. Once I got the simple program running, I tried to figure out if there was a commit that broke this for me in grafana/loki and landed on this one.

grafana/loki#14437 reverts shirou/gopsutil back to v4.24.8, which is before they merged shirou/gopsutil#1702 which I'm suspecting was the problem. I filed a terribly hard to reproduce issue here, but I don't think I understand the problem any better than this to be able to provide more detail.

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

No branches or pull requests

2 participants