MCPcopy
hub / github.com/redis/go-redis / getEffectiveReadTimeout

Method getEffectiveReadTimeout

internal/pool/conn.go:537–566  ·  internal/pool/conn.go::Conn.getEffectiveReadTimeout

getEffectiveReadTimeout returns the timeout to use for read operations. If relaxed timeout is set and not expired, it takes precedence over the provided timeout. This method automatically clears expired relaxed timeouts using atomic operations.

(normalTimeout time.Duration)

Source from the content-addressed store, hash-verified

535// If relaxed timeout is set and not expired, it takes precedence over the provided timeout.
536// This method automatically clears expired relaxed timeouts using atomic operations.
537func (cn *Conn) getEffectiveReadTimeout(normalTimeout time.Duration) time.Duration {
538 readTimeoutNs := cn.relaxedReadTimeoutNs.Load()
539
540 // Fast path: no relaxed timeout set
541 if readTimeoutNs <= 0 {
542 return normalTimeout
543 }
544
545 deadlineNs := cn.relaxedDeadlineNs.Load()
546 // If no deadline is set, use relaxed timeout
547 if deadlineNs == 0 {
548 return time.Duration(readTimeoutNs)
549 }
550
551 // Use cached time to avoid expensive syscall (max 50ms staleness is acceptable for timeout checks)
552 nowNs := getCachedTimeNs()
553 // Check if deadline has passed
554 if nowNs < deadlineNs {
555 // Deadline is in the future, use relaxed timeout
556 return time.Duration(readTimeoutNs)
557 } else {
558 // Deadline has passed, clear relaxed timeouts atomically and use normal timeout
559 newCount := cn.relaxedCounter.Add(-1)
560 if newCount <= 0 {
561 internal.Logger.Printf(context.Background(), logs.UnrelaxedTimeoutAfterDeadline(cn.GetID()))
562 cn.clearRelaxedTimeout()
563 }
564 return normalTimeout
565 }
566}
567
568// getEffectiveWriteTimeout returns the timeout to use for write operations.
569// If relaxed timeout is set and not expired, it takes precedence over the provided timeout.

Callers 2

SetNetConnAndInitConnMethod · 0.95
WithReaderMethod · 0.95

Calls 7

GetIDMethod · 0.95
clearRelaxedTimeoutMethod · 0.95
getCachedTimeNsFunction · 0.85
AddMethod · 0.65
PrintfMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected