os.ErrDeadlineExceeded
GoERRORNotableFilesystem
i/o timeout
Quick Answer
Use errors.Is(err, os.ErrDeadlineExceeded) to detect I/O timeouts and retry or extend the deadline.
What this means
Returned when a file or network I/O operation exceeds its deadline set via SetDeadline. Distinct from context.DeadlineExceeded.
Why it happens
- 1SetDeadline or SetReadDeadline elapsed before the operation completed
- 2Network congestion causing a connection to stall past the deadline
Fix
Extend deadline on retry
Extend deadline on retry
conn.SetDeadline(time.Now().Add(5 * time.Second)) _, err = conn.Read(buf)
Why this works
Resetting the deadline before each operation prevents cumulative timeout drift.
Code examples
Detectgo
if errors.Is(err, os.ErrDeadlineExceeded) {
fmt.Println("I/O timed out")
}Set deadlinego
conn.SetDeadline(
time.Now().Add(3 * time.Second))Retry loopgo
for i := 0; i < 3; i++ {
conn.SetDeadline(time.Now().Add(2 * time.Second))
_, err = conn.Read(buf)
if err == nil { break }
}Same error in other languages
Sources
Official documentation ↗
Go standard library
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev