3

I am trying to debug Go app. Launch config works fine, but seems dlv picking up random port every time debugger starts, which I can see from my logs in console the port is "0"(which means random one):

2021/12/23 15:16:57 Serving on port: 0

Compare to running without debugger:

2021/12/23 15:17:23 Serving on port: 8080

When I type in terminal lsof -i tcp I see the following, the port is random everytime:

__debug_b 19909 userName    7u  IPv6 0xd6d310c29592c12f      0t0  TCP *:60179 (LISTEN)

launch.json config:

{
  "name": "Launch",
  "type": "go",
  "request": "launch",
  "mode": "debug",
  "program": "cmd/main.go",
  "showLog": true,
  "verboseDiagnosticLogging": true,
}

specifying "port" in config doesn't work for me.
Can I somehow configure debugger to pick up a specific port, 8080 in my case?

Ivan S
  • 31
  • 2
  • 2
    "port" in launch.json is for debug server (dlv)'s port, but based on your log message, I guess you want to specify the port used by your Go app. "Serving on port: ..." is not from delve. Make your Go app to accept the port number as an arg or a flag, and specify it using "args" property of the launch.json config. – Hana Dec 29 '21 at 02:11
  • @Hana would you mind writing that up as an answer post please? answers should go in answer posts and not in comments. you may also be interested in linking to https://github.com/golang/vscode-go/blob/v0.38.0/package.json#L735 in your answer post. – starball May 14 '23 at 06:48

0 Answers0