Describe the bug
When using connection pooling and when the DB is offline when the first DB execution occurs, ConnectionPool.PoolSize decrements (in ConnectionPool.RemoveConnection) to a negative number as it keeps failing (throwing exceptions) while creating connections in the CheckAndIncrementPoolSize loop.
When the DB comes back online and connections begin to succeed, the CheckAndIncrementPoolSize loop keeps successfully adding new connections to the pool as it attempts to get the pool size to MinPoolSize.
When PoolSize for example is at -20 when connections start to succeed, it will create 21 connections in the database (when MinPoolSize set to 1). Depending on how negative the number is, it has the potential to use up all the available connections for the server and lock it up.
To Reproduce
The easy way is to pretend db is offline by making your app offline so it can't connect to the DB.
Disconnect internet from the machine running your app.
Start your app and allow it run
Attempt some kind of a query/execution against the DB
(It will fail of course but at this point ConnectionPool has been instantiated and its TryFillPoolToMinSize loop has been kicked off, and as it runs it will keep decrementing PoolSize)
Give it a few minutes and PoolSize will be somewhere around -10 and now connect the internet.
Inspect the DB and notice it starts creating duplicate connections
Expected behaviorPoolSize should never go below zero and thus there should never be extra connections that get created when connection is restored.
Environment
.Net Core version 3.0
AdoNetCore.AseClient nuget package version 0.16.0
Additional context
"Charset=iso_1;Min Pool Size=1;Max Pool Size=5;LoginTimeOut=5;ConnectionIdleTimeout=10; ConnectionLifetime=15;"
Describe the bug When using connection pooling and when the DB is offline when the first DB execution occurs,
ConnectionPool.PoolSize
decrements (inConnectionPool.RemoveConnection
) to a negative number as it keeps failing (throwing exceptions) while creating connections in theCheckAndIncrementPoolSize
loop.When the DB comes back online and connections begin to succeed, the
CheckAndIncrementPoolSize
loop keeps successfully adding new connections to the pool as it attempts to get the pool size to MinPoolSize.When
PoolSize
for example is at -20 when connections start to succeed, it will create 21 connections in the database (whenMinPoolSize
set to 1). Depending on how negative the number is, it has the potential to use up all the available connections for the server and lock it up.To Reproduce The easy way is to pretend db is offline by making your app offline so it can't connect to the DB.
ConnectionPool
has been instantiated and itsTryFillPoolToMinSize
loop has been kicked off, and as it runs it will keep decrementingPoolSize
)PoolSize
will be somewhere around -10 and now connect the internet.Expected behavior
PoolSize
should never go below zero and thus there should never be extra connections that get created when connection is restored.Environment
AdoNetCore.AseClient
nuget package version 0.16.0Additional context "Charset=iso_1;Min Pool Size=1;Max Pool Size=5;LoginTimeOut=5;ConnectionIdleTimeout=10; ConnectionLifetime=15;"