@@ -492,7 +492,12 @@ func (c *TaskCommandRouterClient) ExecStdioRead(
492492 return
493493 }
494494
495- c .streamStdio (ctx , resultCh , taskID , execID , srFd , deadline )
495+ if deadline != nil {
496+ var cancel context.CancelFunc
497+ ctx , cancel = context .WithDeadline (ctx , * deadline )
498+ defer cancel ()
499+ }
500+ c .streamStdio (ctx , resultCh , taskID , execID , srFd )
496501 }()
497502
498503 return resultCh
@@ -529,13 +534,8 @@ func (c *TaskCommandRouterClient) streamStdio(
529534 resultCh chan <- stdioReadResult ,
530535 taskID , execID string ,
531536 fd pb.TaskExecStdioFileDescriptor ,
532- deadline * time.Time ,
533537) {
534- if deadline != nil {
535- var cancel context.CancelFunc
536- ctx , cancel = context .WithDeadline (ctx , * deadline )
537- defer cancel ()
538- }
538+ deadline , hasDeadline := ctx .Deadline ()
539539
540540 var offset int64
541541 delay := 10 * time .Millisecond
@@ -545,7 +545,7 @@ func (c *TaskCommandRouterClient) streamStdio(
545545
546546 for {
547547 if ctx .Err () != nil {
548- if deadline != nil && ctx .Err () == context .DeadlineExceeded {
548+ if hasDeadline && ctx .Err () == context .DeadlineExceeded {
549549 resultCh <- stdioReadResult {Err : ExecTimeoutError {Exception : fmt .Sprintf ("deadline exceeded while streaming stdio for exec %s" , execID )}}
550550 } else {
551551 resultCh <- stdioReadResult {Err : ctx .Err ()}
@@ -573,7 +573,7 @@ func (c *TaskCommandRouterClient) streamStdio(
573573 continue
574574 }
575575 if _ , retryable := commandRouterRetryableCodes [status .Code (err )]; retryable && numRetriesRemaining > 0 {
576- if deadline != nil && time .Until (* deadline ) <= delay {
576+ if hasDeadline && time .Until (deadline ) <= delay {
577577 resultCh <- stdioReadResult {Err : ExecTimeoutError {Exception : fmt .Sprintf ("deadline exceeded while streaming stdio for exec %s" , execID )}}
578578 return
579579 }
@@ -602,7 +602,7 @@ func (c *TaskCommandRouterClient) streamStdio(
602602 break
603603 }
604604 if _ , retryable := commandRouterRetryableCodes [status .Code (err )]; retryable && numRetriesRemaining > 0 {
605- if deadline != nil && time .Until (* deadline ) <= delay {
605+ if hasDeadline && time .Until (deadline ) <= delay {
606606 resultCh <- stdioReadResult {Err : ExecTimeoutError {Exception : fmt .Sprintf ("deadline exceeded while streaming stdio for exec %s" , execID )}}
607607 return
608608 }
0 commit comments