From e0fed4d581392f189a6b6b55b6222956bede467c Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 8 Aug 2019 14:04:19 +0300 Subject: [PATCH] Remove atomic.Value.Store(nil) --- internal/pool/pool_single.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/pool/pool_single.go b/internal/pool/pool_single.go index 3cee769b..6f85b308 100644 --- a/internal/pool/pool_single.go +++ b/internal/pool/pool_single.go @@ -16,6 +16,8 @@ type BadConnError struct { wrapped error } +var _ error = (*BadConnError)(nil) + func (e BadConnError) Error() string { return "pg: Conn is in a bad state" } @@ -178,7 +180,7 @@ func (p *SingleConnPool) Reset() error { return ErrClosed } p.pool.Remove(cn, ErrClosed) - p._badConnError.Store(nil) + p._badConnError.Store(BadConnError{wrapped: nil}) default: return fmt.Errorf("pg: SingleConnPool does not have a Conn") } @@ -193,7 +195,10 @@ func (p *SingleConnPool) Reset() error { func (p *SingleConnPool) badConnError() error { if v := p._badConnError.Load(); v != nil { - return v.(BadConnError) + err := v.(BadConnError) + if err.wrapped != nil { + return err + } } return nil }