dap: fix the race condition in the dap unit tests

The context used for serving the dap server was being canceled too early
because it used defer which would initiate at the end of the function
while every other cleanup function used `t.Cleanup` which executes in
its own goroutine.

One possible solution was to move the cancel to the cleanup, but the
context being passed to serve and start doesn't make sense because if it
ever does get canceled, it'll likely cause a similar race condition with
`Stop`.

This removes the context from the methods that were causing this issue
in favor of just relying on the caller calling `Stop` when they are done
with the adapter and server.

This seems to have only affected tests and I don't believe it affected
the actual dap command.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2026-03-10 12:03:35 -05:00
parent c423bc738b
commit ca9df87014
4 changed files with 13 additions and 14 deletions
+2 -2
View File
@@ -33,11 +33,11 @@ func NewServer(h Handler) *Server {
return &Server{h: h}
}
func (s *Server) Serve(ctx context.Context, conn Conn) error {
func (s *Server) Serve(conn Conn) error {
writeCh := make(chan dap.Message)
s.ch = writeCh
s.ctx, s.cancel = context.WithCancelCause(ctx)
s.ctx, s.cancel = context.WithCancelCause(context.Background())
// Start an error group to handle server-initiated tasks.
s.eg, _ = errgroup.WithContext(s.ctx)