Skip to content

Commit 345940a

Browse files
ezynda3opencode
andcommitted
Fix race condition in stdio.SendRequest with canceled context
Add early context cancellation check to prevent race condition where SendRequest could return nil instead of context.Canceled when called with an already-canceled context. This issue only manifested in certain environments like GitHub Actions due to timing differences. The fix ensures consistent behavior by checking context cancellation before any I/O operations. 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <noreply@opencode.ai>
1 parent 7c38b56 commit 345940a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

client/transport/stdio.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,13 @@ func (c *Stdio) SendRequest(
307307
ctx context.Context,
308308
request JSONRPCRequest,
309309
) (*JSONRPCResponse, error) {
310+
// Check if context is already canceled before doing any work
311+
select {
312+
case <-ctx.Done():
313+
return nil, ctx.Err()
314+
default:
315+
}
316+
310317
if c.stdin == nil {
311318
return nil, fmt.Errorf("stdio client not started")
312319
}

0 commit comments

Comments
 (0)