diff options
Diffstat (limited to 'src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go')
-rw-r--r-- | src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go index 6a9cc634c3b..ee986838100 100644 --- a/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go +++ b/src/mongo/gotools/src/github.com/mongodb/mongo-tools/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/topology/pool.go @@ -116,7 +116,11 @@ func connectionCloseFunc(v interface{}) { return } - go func() { _ = c.pool.closeConnection(c) }() + go func() { + // wait for connection to finish trying to connect + _ = c.wait() + _ = c.pool.closeConnection(c) + }() } // connectionInitFunc returns an init function for the resource pool that will make new connections for this pool @@ -329,7 +333,7 @@ func (p *pool) get(ctx context.Context) (*connection, error) { c.connect(ctx) } - err := c.connectWait() + err := c.wait() if err != nil { if p.monitor != nil { p.monitor.Event(&event.PoolEvent{ @@ -377,7 +381,7 @@ func (p *pool) get(ctx context.Context) (*connection, error) { c.connect(ctx) // wait for conn to be connected - err = c.connectWait() + err = c.wait() if err != nil { if p.monitor != nil { p.monitor.Event(&event.PoolEvent{ @@ -413,10 +417,14 @@ func (p *pool) closeConnection(c *connection) error { if !atomic.CompareAndSwapInt32(&c.connected, connected, disconnected) { return nil // We're closing an already closed connection } - err := c.nc.Close() - if err != nil { - return ConnectionError{ConnectionID: c.id, Wrapped: err, message: "failed to closeConnection net.Conn"} + + if c.nc != nil { + err := c.nc.Close() + if err != nil { + return ConnectionError{ConnectionID: c.id, Wrapped: err, message: "failed to close net.Conn"} + } } + return nil } |