Skip to content

Commit f3ad1ac

Browse files
committed
Fix race condition in context cancellation check
Use select statement instead of ctx.Err() check to avoid race condition when checking for context cancellation in the goroutine error handler. This follows Go best practices for context handling. Addresses review comment from @yrobla.
1 parent 6291c1d commit f3ad1ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

test/integration/vmcp/helpers/vmcp_server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ func NewVMCPServer(
188188
// Start server automatically
189189
// Use the passed-in context to ensure proper cancellation propagation
190190
go func() {
191-
if err := vmcpServer.Start(ctx); err != nil && ctx.Err() == nil {
192-
// Only report error if context wasn't cancelled
193-
tb.Errorf("vMCP server error: %v", err)
191+
if err := vmcpServer.Start(ctx); err != nil {
192+
select {
193+
case <-ctx.Done():
194+
// Context cancelled, ignore error
195+
default:
196+
tb.Errorf("vMCP server error: %v", err)
197+
}
194198
}
195199
}()
196200

0 commit comments

Comments
 (0)