[GODRIVER-389] Race condition when disconnecting a connection pool Created: 27/Apr/18  Updated: 28/Oct/23  Resolved: 28/Apr/18

Status: Closed
Project: Go Driver
Component/s: Connections
Affects Version/s: 0.0.3
Fix Version/s: 0.0.4

Type: Bug Priority: Critical - P2
Reporter: Kristofer Brandow (Inactive) Assignee: Kristofer Brandow (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

If a user calls pool.Disconnect while another goroutine is closing a Connection from that pool, a series of context switches may allow a connection to enter the idle pool after the Disconnect method has cleared the connections from the idle pool. This results in a deadlock wherein a user who used a context without a deadline or timeout will wait forever since we cannot acquire all the permits from the semaphore, nor can we retrieve the connection from the idle pool.

To solve this problem, add a RWMutex that is used in pool.Disconnect and pool.returnConnection. Since it is possible for a Connection to block forever, this RWMutex should be released before calling pool.closeConnection. The pool.Disconnect method should acquire the mutex in write more before clearing the connection pool.



 Comments   
Comment by Githook User [ 28/Apr/18 ]

Author:

{'email': 'kris@mongodb.com', 'username': 'skriptble', 'name': 'Kris Brandow'}

Message: Fix race conditions and leaks in connection pool

GODRIVER-388
GODRIVER-389
GODRIVER-390

Change-Id: I1390c184beb379d4cc775ba07b5d222342dc957e
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/98f5b78d43c7bf8cb246de3d102867ea26d3b49d

Comment by Kristofer Brandow (Inactive) [ 27/Apr/18 ]

Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/409354.

Generated at Thu Feb 08 08:34:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.