diff --git a/service/dap/server.go b/service/dap/server.go index 49be9feb..b6b4de5f 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -269,13 +269,6 @@ func (s *Server) Stop() { s.mu.Lock() defer s.mu.Unlock() - if s.conn != nil { - // Unless Stop() was called after serveDAPCodec() - // returned, this will result in closed connection error - // on next read, breaking out of the read loop and - // allowing the run goroutine to exit. - _ = s.conn.Close() - } if s.debugger != nil { killProcess := s.config.Debugger.AttachPid == 0 @@ -286,7 +279,15 @@ func (s *Server) Stop() { // The binary is no longer in use by the debugger. It is safe to remove it. if s.binaryToRemove != "" { gobuild.Remove(s.binaryToRemove) - s.binaryToRemove = "" + } + // Close client connection last, so other shutdown stages + // can send client notifications + if s.conn != nil { + // Unless Stop() was called after serveDAPCodec() + // returned, this will result in closed connection error + // on next read, breaking out of the read loop and + // allowing the run goroutine to exit. + _ = s.conn.Close() } s.log.Debug("DAP server stopped") }