-
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
service/dap: refine teardown logic #2414
Conversation
service/dap/server.go
Outdated
} | ||
|
||
func (s *Server) stopDebugSession(killProcess bool) { | ||
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.Halt}, 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.
Why doesn't rpc server halt in Stop()?
delve/service/rpccommon/server.go
Lines 91 to 97 in c223ef6
func (s *ServerImpl) Stop() error { | |
if s.config.AcceptMulti { | |
close(s.stopChan) | |
s.listener.Close() | |
} | |
kill := s.config.Debugger.AttachPid == 0 | |
return s.debugger.Detach(kill) |
On a related note, the terminology collision here is unfortunate: https://github.com/go-delve/delve/blob/master/Documentation/api/ClientHowto.md#gracefully-ending-the-debug-session
From the RPC client point of view, it appears that
- Detach = detach debugger from the process (maybe kill it) + close client connection
- Disconnect = close client connection
But the client how-to uses a phrase "disconnecting a running program" as a case where Detach is called. And then we have DAP where disconnect request is sent to "disconnect from the debuggee and to terminate the debug adapter". Sigh.
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.
Wild guess - isn't it because it's the rpc client who is supposed to call Halt (or Disconnect) command before the server stops. Not sure about the case where the debugging stops because client unexpectedly crashes or gets disconnected.
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.
That's precisely the case I was thinking about. The client takes care of Halt before Detach. But if there is an error reading rpc messages from client, the server will go into shutdown mode and call Stop() without halting.
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.
I don't think there's a particular reason, halting would probably be better. And the client howto should say detach where it says ""disconnecting a running program".
Test failure is unrelated: |
cc @hyangah |
service/dap/server.go
Outdated
} | ||
|
||
func (s *Server) stopDebugSession(killProcess bool) { | ||
_, err := s.debugger.Command(&api.DebuggerCommand{Name: api.Halt}, 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.
Wild guess - isn't it because it's the rpc client who is supposed to call Halt (or Disconnect) command before the server stops. Not sure about the case where the debugging stops because client unexpectedly crashes or gets disconnected.
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.
PTAL
Failing tests are unrelated: |
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.
Thanks!
I don't know enough to review the Halt + Detach logic so still need review from delve maintainers. Other parts look good to me.
p := s.noDebugProcess | ||
s.noDebugProcess = nil | ||
defer s.mu.Unlock() |
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.
@hyangah Was this meant to be regular unlock to minimize scope (hence the temp var p var)? With my new change, the entire function gets locked (so I shouldn't need p
anymore). Not ideal? But at the same time, what else is there to do when we are existing?
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.
Heh, this is a bug - I meant s.mu.Unlock(), not defer s.mu.Unlock. :-)
Yeah, the intention was to reduce the scope - so the goroutine that's blocked onLaunchRequest (waiting for the termination of s.nodebugProcess) can proceed as soon as it's unblocked when p's killed. But you're right. We don't need to be too clever here.
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.
Thanks for clarifying. I remove the temp var "p".
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
@suzmue |
Fix at #2417 |
Needs rebase, I'll TAL tomorrow. |
I am working on the merge. |
FailedToAttach, "Failed to attach", err.Error()) | ||
func() { | ||
s.mu.Lock() | ||
defer s.mu.Unlock() // Make sure to unlock in case of panic that will become internal error |
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.
I am not sure why this did not show up before the merge, but there is a test in TestBadAttachRequest with negative attach pid that resulted in a panic from debugger.New that skipped releasing the lock and then disconnect was forever waiting to acquire it. I changed onLaunchRequest in a similar way as well just in case.
Unrelated TeamCity failure: |
@derekparker Is there more to be done to get this PR in? It would be great to get it out of the way to resolve more conflicts in subsequent PRs. Thank you. |
* service/dap: refine teardown logic * Address review comments + add missing lock/unlock * Narrow lock scope * Update comments only * Remove redundan temp var from stopNoDebugProcess * Clarify comment * Set debugger to nil after detach to prevent dup teardown in Stop() Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
Updates #1515