[GODRIVER-390] Getting a connection from a pool can be starved indefinitely 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: Major - P3
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   

In an application where the maximum number of connections has been dialed and they are all in use, attempting to get a new connection will wait, attempting to acquire a semaphore. If the application has further heavy load and the idle pool is never filled, no connections will be closed, which will indefinitely starve the attempt to get a new connection.

To fix this problem:

  1. Refactor the code so that dialing a new connection is it's own function that takes a context and a channel.
  2. If we can acquire a permit from the semaphore, dial the connection and return it down the provided channel. If the context has been canceled, we close the connection, because the Get method received a connection from the idle pool or canceled the context for another reason.
  3. In the main Get method, attempt to first retrieve a connection from the idle pool, and if that cannot be done, then call the new connection method in a goroutine and block on either the new connection, an idle pool connection, or for the context's done channel. If either the context done channel or the idle pool connection channel unblock, cancel the new connection context.


 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.