DataAction / AdoNetCore.AseClient

AdoNetCore.AseClient - a .NET Core DB Provider for SAP ASE
Apache License 2.0
106 stars 44 forks source link

When DB is offline at app start, duplicate connections spawn after connection restored #158

Closed ts46235 closed 4 years ago

ts46235 commented 4 years ago

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.

  1. Disconnect internet from the machine running your app.
  2. Start your app and allow it run
  3. 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)
  4. Give it a few minutes and PoolSize will be somewhere around -10 and now connect the internet.
  5. Inspect the DB and notice it starts creating duplicate connections

Expected behavior PoolSize should never go below zero and thus there should never be extra connections that get created when connection is restored.

Environment

Additional context "Charset=iso_1;Min Pool Size=1;Max Pool Size=5;LoginTimeOut=5;ConnectionIdleTimeout=10; ConnectionLifetime=15;"