In timeout.go, context cancellation isn't check for when running the command goroutine. This causes the errc <- next.Run(ctx, f) call to block indefinitely if the command times out.
ctx, _ = context.WithTimeout(ctx, cfg.Timeout)
// Run the command
errc := make(chan error)
go func() {
errc <- next.Run(ctx, f) //This blocks indefinitely if the context is cancelled due to a timeout.
}()
// Wait until the deadline has been reached or we have a result.
select {
// Finished correctly.
case err := <-errc:
return err
// Timeout.
case <-ctx.Done():
metricsRecorder.IncTimeout()
return errors.ErrTimeout
}
The simple fix is to select:
go func() {
select {
case <-ctx.Done():
case errc <- next.Run(ctx, f):
}
}()
In
timeout.go, context cancellation isn't check for when running the command goroutine. This causes theerrc <- next.Run(ctx, f)call to block indefinitely if the command times out.The simple fix is to select: