Skip to content

Commit

Permalink
no closing connections mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sleygin committed Dec 21, 2023
1 parent 9ab9e3c commit 6669de7
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 39 deletions.
4 changes: 4 additions & 0 deletions pgconn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ type Config struct {
// that you close on FATAL errors by returning false.
OnPgError PgErrorHandler

// NoClosingConnMode enables mode when connections are not closed when timeout happens but cleaned up
// and returned back to the pool.
NoClosingConnMode bool

createdByParseConfig bool // Used to enforce created by ParseConfig rule.
}

Expand Down
14 changes: 8 additions & 6 deletions pgconn/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func (e *connectError) Unwrap() error {
return e.err
}

var ErrLockCleanupConn = &connLockError{status: "conn need to cleanup"}

type connLockError struct {
status string
}
Expand Down Expand Up @@ -163,25 +165,25 @@ func (e *errTimeout) Unwrap() error {
return e.err
}

type contextAlreadyDoneError struct {
type ContextAlreadyDoneError struct {
err error
}

func (e *contextAlreadyDoneError) Error() string {
func (e *ContextAlreadyDoneError) Error() string {
return fmt.Sprintf("context already done: %s", e.err.Error())
}

func (e *contextAlreadyDoneError) SafeToRetry() bool {
func (e *ContextAlreadyDoneError) SafeToRetry() bool {
return true
}

func (e *contextAlreadyDoneError) Unwrap() error {
func (e *ContextAlreadyDoneError) Unwrap() error {
return e.err
}

// newContextAlreadyDoneError double-wraps a context error in `contextAlreadyDoneError` and `errTimeout`.
// newContextAlreadyDoneError double-wraps a context error in `ContextAlreadyDoneError` and `errTimeout`.
func newContextAlreadyDoneError(ctx context.Context) (err error) {
return &errTimeout{&contextAlreadyDoneError{err: ctx.Err()}}
return &errTimeout{&ContextAlreadyDoneError{err: ctx.Err()}}
}

func redactPW(connString string) string {
Expand Down
Loading

0 comments on commit 6669de7

Please sign in to comment.