-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
cmd/dlv: add --continue to continue process on launch/attach #1585
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works technically, but there is an issue here. The main use case for this feature would be to start a headless delve server (for example within a container) and then attach to it. However when the headless server is running and I try to connect to it the client just hangs. It connects to the socket, but when it tries to make the initial RPC call to set API version it will wait forever for the server, which is waiting for the process, so the RPC call will never be addressed.
This patch needs to address this possibly by having the server detect a new connection and stopping the process if it is running so the user can start issuing commands, etc.
service/debugger/debugger.go
Outdated
@@ -57,6 +57,9 @@ type Config struct { | |||
// attach. | |||
AttachPid int | |||
|
|||
// ContinueOnStart determiend whether the new process should be paused on start. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spelling error: s/determiend/determines/
cc @aarzilli for your thoughts as well. |
Sorry for wasting your time @derekparker — I hadn't tested this in an end-to-end situation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works technically, but there is an issue here. The main use case for this feature would be to start a headless delve server (for example within a container) and then attach to it. However when the headless server is running and I try to connect to it the client just hangs
The reason this happens is that the Continue call is done in debugger.New
: the call never terminates and the server never finishes initializing and never starts actually accepting connections (the socket however is already open, which is why the connect
doesn't fail completely).
The call to continue needs to happen at some point after the server initialization is finished.
service/debugger/debugger.go
Outdated
@@ -99,6 +102,11 @@ func New(config *Config, processArgs []string) (*Debugger, error) { | |||
return nil, attachErrorMessage(d.config.AttachPid, err) | |||
} | |||
d.target = p | |||
if d.config.ContinueOnStart { | |||
if _, err := d.target.ContinueOnce(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContinueOnce shouldn't be called directly, it should be proc.Continue
.
cmd/dlv/cmds/commands.go
Outdated
@@ -240,6 +246,7 @@ to know what functions your process is executing.`, | |||
traceCommand.Flags().BoolVarP(&traceTestBinary, "test", "t", false, "Trace a test binary.") | |||
traceCommand.Flags().IntVarP(&traceStackDepth, "stack", "s", 0, "Show stack trace with given depth.") | |||
traceCommand.Flags().String("output", "debug", "Output path for the binary.") | |||
traceCommand.Flags().BoolVar(&ContinueOnStart, "continue", false, "Continue the traced process on start.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trace command always continues automatically, there's no need for this.
Thanks — I'll fix this up and do more comprehensive testing. |
Not a waste of time, just doing my due diligence! I appreciate this PR as it's been a much requested one! |
@briandealwis ping on this. |
Sorry, I was pulled away with holidays and other work. My attempt to use a client like the traceCmd hasn't worked out: dlv just exits. I'll be digging into this tomorrow. |
So it seemed to make sense to limiting I'm currently looking at whether I can do this at a lower level |
Fatfingered the close button. Would this be better done at lower levels the stack? Unfortunately I can't seem to debug delve with delve on macOS to get a better understanding of what's going on: I get some ioctl error from the second lldb debugserver. |
The trace command could be used as a starting point, I think. But I'm not sure what you mean by "dlv just exits". What does the process look like that you're testing against? Is it a server or something that is intended to be long running? Is there any output when delve exits? Is Delve exiting before the process does? |
No, I think this level is the correct one. AcceptMulti is necessary because otherwise the whole thing would be useless (you'd have a process running under delve but no way to connect to delve itself).
This is always the case, if you run a program under delve and the program terminates you go back to delve's prompt. |
Sorry for lack of response: I was away at a lake and forbidden from touching a laptop :-) I realize my comments above were from an odd behaviour I hit where
I should have provided some context. My driving use-case is to leverage Delve to allow debugging containerized Go programs in a Kubernete cluster as part of Skaffold(tracked as GoogleContainerTools/skaffold#2306). In the Kubernetes case, once the user has finished their debugging session and stops the application, then we want the container to exit so that Kubernetes can do its magic and relaunch the container. As I noticed with #1617, if the application has exited normally then the headless instance becomes unkillable (at least with the dlv terminal client), and the container appears to hang. (I suppose Kubernetes will eventually deem the container as being unhealthy and restart it?) (I didn't test whether the RPC detach will properly cause the headless dlv process to exit.) |
No worries, it's good to unplug for a bit! Saw you pushed some updates but the tests are failing in CI. Does everything pass for you locally? |
The tests are timing out on the
on the test in `_fixtures/buildtest/main.go. But I just realized that test doesn't make sense in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation/faq.md should be changed, to say at the end:
If you want the program to start immediately you can do that by passing the `--continue` option the dlv
service/config.go
Outdated
@@ -13,6 +13,8 @@ type Config struct { | |||
Listener net.Listener | |||
// ProcessArgs are the arguments to launch a new process. | |||
ProcessArgs []string | |||
// ContinueOnStart determines whether the new process should be continued on start. | |||
ContinueOnStart bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I missing something or this isn't used?
service/debugger/debugger.go
Outdated
@@ -57,6 +57,9 @@ type Config struct { | |||
// attach. | |||
AttachPid int | |||
|
|||
// ContinueOnStart determines whether the new process should be paused on start. | |||
ContinueOnStart bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the patch! |
…e#1585) * Add --continue to continue process on launch/attach * Add small test of --continue * regenerate usage docs * minor cleanup * Use similar approach to `trace` and connect and detach using a client instance * back out previous attempt * regen usage doc * fix up continue test * fix TestContinue to properly test --continue * back out unnecessary changes * update faq
…e#1585) * Add --continue to continue process on launch/attach * Add small test of --continue * regenerate usage docs * minor cleanup * Use similar approach to `trace` and connect and detach using a client instance * back out previous attempt * regen usage doc * fix up continue test * fix TestContinue to properly test --continue * back out unnecessary changes * update faq
Add
--continue
option forattach
,debug
,exec
, andtrace
, to issue a continue on start.Fixes #245