Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions pgconn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ func (e *ParseConfigError) Unwrap() error {

func normalizeTimeoutError(ctx context.Context, err error) error {
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() {
if ctx.Err() == context.Canceled {
// Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error.
return context.Canceled
} else if ctx.Err() == context.DeadlineExceeded {
return &errTimeout{err: ctx.Err()}
} else {
return &errTimeout{err: netErr}
}
if !errors.As(err, &netErr) || !netErr.Timeout() {
return err
}

ctxErr := ctx.Err()
if ctxErr == nil {
return &errTimeout{err: netErr}
}
return err

if errors.Is(ctxErr, context.Canceled) {
// Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error.
return context.Canceled
}

return &errTimeout{err: ctxErr}
}

type pgconnError struct {
Expand Down