-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 0.0.3
-
Component/s: Connections
-
None
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:
Refactor the code so that dialing a new connection is it's own function that takes a context and a channel.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.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.