You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The connection pool is only useful when writing concurrent code, but it doesn't actually stop multiple goroutines from accessing the same connection simultaneously.
To Reproduce
The PR includes a test suite that reproduces the issue with the old Pool code, so long as it's edited to include the afterAcquire and beforeRelease test hooks.
Expected behavior
Pool.Exec(), Pool.Ping(), Pool.Query(), and Pool.Server() are safe for concurrent use. Two calls can only use the same connection serially.
When a query is submitted to the pool,
If there is an unused connection in the pool, it will be used to run the query immediately.
Otherwise, the pool will wait for a connection to become available and then run the query.
A connection is only returned to the pool when it is safe to do so.
Cursors perform their work via the connection, which means if the pool returns a cursor, the connection cannot be returned to the pool until the cursor is closed.
Additional context
Problems with the prior pool implementation:
Pool.conn() uses the connections in round-robin order without checking if they are still in use. It appears queries and cursors can be multiplexed on one connection, so this would work fine in the single goroutine case. However, if multiple goroutines call the Pool there is no guarantee each Connection will only be used by one goroutine at a time.
Describe the bug
The connection pool is only useful when writing concurrent code, but it doesn't actually stop multiple goroutines from accessing the same connection simultaneously.
To Reproduce
The PR includes a test suite that reproduces the issue with the old Pool code, so long as it's edited to include the
afterAcquire
andbeforeRelease
test hooks.Expected behavior
Pool.Exec()
,Pool.Ping()
,Pool.Query()
, andPool.Server()
are safe for concurrent use. Two calls can only use the same connection serially.Screenshots
n/a
System info
n/a
Additional context
Problems with the prior pool implementation:
Pool.conn()
uses the connections in round-robin order without checking if they are still in use. It appears queries and cursors can be multiplexed on one connection, so this would work fine in the single goroutine case. However, if multiple goroutines call thePool
there is no guarantee eachConnection
will only be used by one goroutine at a time.Similarly there is a race condition in the lines:
Suppose
pointer == 9
andlen(conns) == 10
. Three goroutines could run in this sequence:Because there is no "in use" check, two of the goroutines end up using the same
Connection
.The text was updated successfully, but these errors were encountered: