2
0

Context errors returned instead of net.Error

The net.Error caused by using SetDeadline to implement context
cancellation shouldn't leak.

fixes #80
This commit is contained in:
Jack Christensen
2021-07-24 09:09:22 -05:00
parent 13d454882b
commit 6996e8d6c5
3 changed files with 28 additions and 15 deletions
+10
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net"
"net/url"
"regexp"
"strings"
@@ -105,6 +106,15 @@ func (e *parseConfigError) Unwrap() error {
return e.err
}
// preferContextOverNetTimeoutError returns ctx.Err() if ctx.Err() is present and err is a net.Error with Timeout() ==
// true. Otherwise returns err.
func preferContextOverNetTimeoutError(ctx context.Context, err error) error {
if err, ok := err.(net.Error); ok && err.Timeout() && ctx.Err() != nil {
return &errTimeout{err: ctx.Err()}
}
return err
}
type pgconnError struct {
msg string
err error