Why does 'dlv connect' result in 'Command failed: connection is shut down' during remote debugging session in a container with port-forwarding?

269 views Asked by At

dlv connect results in Command failed: connection is shut down

I want to connect to delve (Go debugger) remotely and run a debugging session for the process in a container. But when I do dlv connect, it takes very long for it to connect but once it does, the port-forward connection is lost and renders the connected debugging session useless.

  • What version of Delve are you using (dlv version)? Version: 1.20.2
  • What version of Go are you using? (go version)? go1.20.1 linux/amd64
  • What operating system and processor architecture are you using? VM with ubuntu/bionic64
  • What did you do?

I have delve in a container and did port-forwarding to do the debugging from the host machine. When I issue the command dlv connect localhost:40000 --api-version=2 --log, it takes very long time for this to show:

Type 'help' for list of commands. 

dlv port-forwarding shows this output:

Handling connection for 40000 E0529 05:04:24.566631    7075 portforward.go:409] an error occurred forwarding 40000 -> 40000: error forwarding port 40000 to pod 10b0190afd8de916d3574fe2a020652c7d40e9bae7a64041f223f09bf830457c, uid : failed to execute portforward in network namespace "host": failed to connect to localhost:40000 inside namespace "10b0190afd8de916d3574fe2a020652c7d40e9bae7a64041f223f09bf830457c", IPv4: dial tcp4 127.0.0.1:40000: connect: cannot assign requested address IPv6 dial tcp6: address localhost: no suitable address found error: lost connection to pod

So, any further commands in the debugging session result in Command failed: connection is shut down For instance:

dlv connect localhost:40000 --api-version=2 --log Type 'help' for list of commands. (dlv) list main.main Command failed: connection is shut down (dlv) bp Command failed: connection is shut down (dlv) q connection is shut down

What did you expect to see? Smooth functioning of the remote debugging. No connection loss is expected.

What did you see instead? Command failed: connection is shut down Unable to perform debugging.

My container has the following command included:

CMD ["/dlv", "--listen=:40000", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/usr/local/bin/app"]

How can I fix this to have a smooth remote debugging session ?

0

There are 0 answers