Skip to content

Commit

Permalink
feat: handle i/o timeouts as transient timeout errors
Browse files Browse the repository at this point in the history
Ensures i/o timeouts are forwarded as DeadlineExceeded transient errors
to callers, which in turn ensures these errors are retried automatically.
  • Loading branch information
odsod committed Jun 5, 2024
1 parent 261c734 commit 331d026
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clouderror/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"os"
"runtime"
"syscall"

Expand Down Expand Up @@ -47,6 +48,8 @@ func WrapTransientCaller(err error, msg string, caller Caller) error {
return &wrappedStatusError{status: status.New(codes.Unavailable, msg), err: err, caller: caller}
case errors.As(err, &http2.GoAwayError{}):
return &wrappedStatusError{status: status.New(codes.Unavailable, msg), err: err, caller: caller}
case os.IsTimeout(err):
return &wrappedStatusError{status: status.New(codes.Unavailable, msg), err: err, caller: caller}
default:
return &wrappedStatusError{status: status.New(codes.Internal, msg), err: err, caller: caller}
}
Expand Down
6 changes: 6 additions & 0 deletions clouderror/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clouderror
import (
"context"
"fmt"
"os"
"testing"

"golang.org/x/net/http2"
Expand Down Expand Up @@ -80,6 +81,11 @@ func Test_WrapTransient(t *testing.T) {
},
expectedCode: codes.Unavailable,
},
{
name: "os timeout error",
err: os.ErrDeadlineExceeded,
expectedCode: codes.Unavailable,
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 331d026

Please sign in to comment.