Skip to content

Commit

Permalink
service/dap: send terminated event when disconnecting (#2587)
Browse files Browse the repository at this point in the history
* service/dap: send terminated event when disconnecting

If the program terminates while disconnecting, either because it
was killed or otherwise, send a terminated event.
  • Loading branch information
suzmue authored Jul 14, 2021
1 parent 175ca0c commit 890cde3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/dlv/dlv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ func TestDap(t *testing.T) {
client := daptest.NewClient(listenAddr)
client.DisconnectRequest()
client.ExpectDisconnectResponse(t)
client.ExpectTerminatedEvent(t)
if _, err := client.ReadMessage(); err != io.EOF {
t.Errorf("got %q, want \"EOF\"\n", err)
}
Expand Down
4 changes: 4 additions & 0 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,10 @@ func (s *Server) onDisconnectRequest(request *dap.DisconnectRequest) {
} else {
s.send(&dap.DisconnectResponse{Response: *newResponse(request.Request)})
}
// The debugging session has ended, so we send a terminated event.
s.send(&dap.TerminatedEvent{
Event: *newEvent("terminated"),
})
}

// stopDebugSession is called from Stop (main goroutine) and
Expand Down
7 changes: 7 additions & 0 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func TestLaunchStopOnEntry(t *testing.T) {
if dResp.Seq != 0 || dResp.RequestSeq != 13 {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=13", dResp)
}
client.ExpectTerminatedEvent(t)
})
}

Expand Down Expand Up @@ -377,6 +378,7 @@ func TestAttachStopOnEntry(t *testing.T) {
client.CheckOutputEvent(t, msg)
msg = expectMessageFilterStopped(t, client)
client.CheckDisconnectResponse(t, msg)
client.ExpectTerminatedEvent(t)

// If this call to KeepAlive isn't here there's a chance that stdout will
// be garbage collected (since it is no longer alive long before this
Expand Down Expand Up @@ -452,6 +454,7 @@ func TestContinueOnEntry(t *testing.T) {
if dResp.Seq != 0 || dResp.RequestSeq != 8 {
t.Errorf("\ngot %#v\nwant Seq=0, RequestSeq=8", dResp)
}
client.ExpectTerminatedEvent(t)
})
}

Expand Down Expand Up @@ -591,6 +594,7 @@ func TestPreSetBreakpoint(t *testing.T) {
client.ExpectOutputEventProcessExited(t, 0)
client.ExpectOutputEventDetaching(t)
client.ExpectDisconnectResponse(t)
client.ExpectTerminatedEvent(t)
})
}

Expand Down Expand Up @@ -3854,6 +3858,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
client.ExpectOutputEventDetachingKill(t)
}
client.ExpectDisconnectResponse(t)
client.ExpectTerminatedEvent(t)
return
}
client.ContinueRequest(1)
Expand All @@ -3872,6 +3877,7 @@ func runDebugSessionWithBPs(t *testing.T, client *daptest.Client, cmd string, cm
client.ExpectOutputEventDetachingKill(t)
}
client.ExpectDisconnectResponse(t)
client.ExpectTerminatedEvent(t)
}

// runDebugSession is a helper for executing the standard init and shutdown
Expand Down Expand Up @@ -3996,6 +4002,7 @@ func runNoDebugDebugSession(t *testing.T, client *daptest.Client, cmdRequest fun
client.ExpectTerminatedEvent(t)
client.DisconnectRequestWithKillOption(true)
client.ExpectDisconnectResponse(t)
client.ExpectTerminatedEvent(t)
}

func TestLaunchTestRequest(t *testing.T) {
Expand Down

0 comments on commit 890cde3

Please sign in to comment.