fix: keep Redis timeouts below a second exact
A checker's long poll ends with BLPOP waiting the rest of it, often below a second, which go-redis rounded up to one second with a warning in the log; the poll then ran up to a second too long. Such waits now pass BLPOP a fraction of a second, which Redis takes since 6.0. A session's sliding expiry, which can be below a second near its absolute end, uses PEXPIRE. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
db36d918fe
commit
66537f4e65
3 files changed
+28
-3
No files matched your search
@@ -281,7 +281,7 @@ func (s *Scheduler) Take(ctx context.Context, instance uuid.UUID, max int, wait
|
||||
return nil, nil
|
||||
}
|
||||
// BLPOP blocks server side and ignores ctx, so wait in slices.
|
||||
first, err := s.rdb.BLPop(ctx, min(left, time.Second), q).Result()
|
||||
first, err := s.blpop(ctx, min(left, time.Second), q)
|
||||
if errors.Is(err, redis.Nil) {
|
||||
continue
|
||||
}
|
||||
@@ -306,6 +306,15 @@ func (s *Scheduler) Take(ctx context.Context, instance uuid.UUID, max int, wait
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// blpop is BLPOP with a timeout below a second, which go-redis would round
|
||||
// up to one (Redis takes fractions of seconds since 6.0).
|
||||
func (s *Scheduler) blpop(ctx context.Context, timeout time.Duration, key string) ([]string, error) {
|
||||
if timeout >= time.Second {
|
||||
return s.rdb.BLPop(ctx, timeout, key).Result()
|
||||
}
|
||||
return s.rdb.Do(ctx, "BLPOP", key, strconv.FormatFloat(timeout.Seconds(), 'f', 3, 64)).StringSlice()
|
||||
}
|
||||
|
||||
// Release returns instance's queued runs to its region and forgets it.
|
||||
func (s *Scheduler) Release(ctx context.Context, region string, instance uuid.UUID) error {
|
||||
// Marking the instance stale lets the dispatch script do the handover,
|
||||
|
||||
Reference in new issue
Block a user