Skip to content

Commit ccb602a

Browse files
authored
Busy list in pool handling in case of an error (DNET-916). (#91)
1 parent a629d28 commit ccb602a

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnection.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public override void Open()
457457

458458
if (_options.Pooling)
459459
{
460-
FbConnectionPoolManager.Instance.Release(_innerConnection);
460+
FbConnectionPoolManager.Instance.Release(_innerConnection, true);
461461
}
462462
else
463463
{
@@ -511,26 +511,16 @@ public override void Close()
511511
_innerConnection.EnableCancel();
512512
}
513513

514-
if (!_innerConnection.Database.ConnectionBroken)
514+
var broken = _innerConnection.Database.ConnectionBroken;
515+
FbConnectionPoolManager.Instance.Release(_innerConnection, !broken);
516+
if (broken)
515517
{
516-
FbConnectionPoolManager.Instance.Release(_innerConnection);
517-
}
518-
else
519-
{
520-
if (!_innerConnection.IsEnlisted)
521-
{
522-
_innerConnection.Dispose();
523-
}
524-
_innerConnection = null;
518+
EnlistedHelper();
525519
}
526520
}
527521
else
528522
{
529-
if (!_innerConnection.IsEnlisted)
530-
{
531-
_innerConnection.Dispose();
532-
}
533-
_innerConnection = null;
523+
EnlistedHelper();
534524
}
535525
}
536526
catch
@@ -540,6 +530,15 @@ public override void Close()
540530
OnStateChange(_state, ConnectionState.Closed);
541531
}
542532
}
533+
534+
void EnlistedHelper()
535+
{
536+
if (!_innerConnection.IsEnlisted)
537+
{
538+
_innerConnection.Dispose();
539+
}
540+
_innerConnection = null;
541+
}
543542
}
544543

545544
#endregion

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbConnectionPoolManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ public FbConnectionInternal GetConnection(FbConnection owner)
9292
}
9393
}
9494

95-
public void ReleaseConnection(FbConnectionInternal connection)
95+
public void ReleaseConnection(FbConnectionInternal connection, bool returnToAvailable)
9696
{
9797
lock (_syncRoot)
9898
{
9999
CheckDisposedImpl();
100100

101101
var removed = _busy.Remove(connection);
102-
if (removed)
102+
if (removed && returnToAvailable)
103103
{
104104
_available.Push(new Item(GetTicks(), connection));
105105
}
@@ -196,11 +196,11 @@ internal FbConnectionInternal Get(ConnectionString connectionString, FbConnectio
196196
return _pools.GetOrAdd(connectionString.NormalizedConnectionString, _ => new Pool(connectionString)).GetConnection(owner);
197197
}
198198

199-
internal void Release(FbConnectionInternal connection)
199+
internal void Release(FbConnectionInternal connection, bool returnToAvailable)
200200
{
201201
CheckDisposed();
202202

203-
_pools.GetOrAdd(connection.Options.NormalizedConnectionString, _ => new Pool(connection.Options)).ReleaseConnection(connection);
203+
_pools.GetOrAdd(connection.Options.NormalizedConnectionString, _ => new Pool(connection.Options)).ReleaseConnection(connection, returnToAvailable);
204204
}
205205

206206
internal void ClearAllPools()

0 commit comments

Comments
 (0)