Skip to content

Commit

Permalink
Align Write timeout handling with Read timeout handling
Browse files Browse the repository at this point in the history
In hashicorp#31, the Read path was changed to move away from
time.After. This change was not reflected in the Write path, and this
commit rectifies that.
  • Loading branch information
lattwood committed Jun 14, 2024
1 parent 9a1a4f1 commit 20a27f7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,11 @@ START:

WAIT:
var timeout <-chan time.Time
var timer *time.Timer
writeDeadline := s.writeDeadline.Load().(time.Time)
if !writeDeadline.IsZero() {
delay := writeDeadline.Sub(time.Now())
timer = time.NewTimer(delay)
timeout = time.After(delay)
}
select {
Expand All @@ -231,6 +233,9 @@ WAIT:
case <-timeout:
return 0, ErrTimeout
}
if timer != nil {
timer.Stop()
}
goto START
}

Expand Down

0 comments on commit 20a27f7

Please sign in to comment.