Skip to content

Commit a0e3627

Browse files
committed
fix(streams): downgrade i/o timeout to WARN and add backoff on errors
Managed Redis providers (Upstash, Redis Cloud) terminate idle connections after ~10 s, which surfaces as an i/o timeout on the blocking XReadGroup call. go-redis reconnects automatically on the next attempt, so these are not real errors — log them at WARN and retry immediately. For genuine unexpected errors, sleep 500 ms before retrying so the loop does not hammer Redis when it is actually unhealthy.
1 parent 6280ab6 commit a0e3627

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎backend/internal/infrastructure/streams/consumer.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package streams
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"log/slog"
8+
"net"
9+
"time"
710

811
"github.com/redis/go-redis/v9"
912
)
@@ -54,7 +57,21 @@ func (c *Consumer) Run(ctx context.Context, h Handler) error {
5457
if err == redis.Nil {
5558
continue
5659
}
60+
// Managed Redis (Upstash, Redis Cloud) kills idle connections, which
61+
// surfaces as an i/o timeout on the blocking XReadGroup call. The
62+
// go-redis pool reconnects automatically on the next attempt, so
63+
// treat this as WARN and retry without delay.
64+
var netErr net.Error
65+
if errors.As(err, &netErr) && netErr.Timeout() {
66+
slog.Warn("streams: connection timeout, reconnecting", "stream", c.stream)
67+
continue
68+
}
5769
slog.Error("streams: read error", "stream", c.stream, "err", err)
70+
select {
71+
case <-ctx.Done():
72+
return nil
73+
case <-time.After(500 * time.Millisecond):
74+
}
5875
continue
5976
}
6077
for _, entry := range entries {

0 commit comments

Comments
 (0)