Skip to content

Commit 0e165ca

Browse files
committed
Using absolute time for connection lifetime checking (DNET-787).
1 parent 37565d2 commit 0e165ca

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Collections.Concurrent;
2121
using System.Collections.Generic;
2222
using System.Linq;
23-
using System.Text;
2423
using System.Threading;
2524
using System.Threading.Tasks;
2625
using FirebirdSql.Data.Common;
@@ -42,10 +41,10 @@ sealed class Item : IDisposable
4241
{
4342
bool _disposed;
4443

45-
public DateTimeOffset Created { get; private set; }
44+
public long Created { get; private set; }
4645
public FbConnectionInternal Connection { get; private set; }
4746

48-
public Item(DateTimeOffset created, FbConnectionInternal connection)
47+
public Item(long created, FbConnectionInternal connection)
4948
{
5049
Created = created;
5150
Connection = connection;
@@ -56,7 +55,7 @@ public void Dispose()
5655
if (_disposed)
5756
return;
5857
_disposed = true;
59-
Created = default(DateTimeOffset);
58+
Created = default(long);
6059
Connection.Dispose();
6160
Connection = null;
6261
}
@@ -114,7 +113,7 @@ public void ReleaseConnection(FbConnectionInternal connection)
114113
var removed = _busy.Remove(connection);
115114
if (removed)
116115
{
117-
_available.Push(new Item(DateTimeOffset.UtcNow, connection));
116+
_available.Push(new Item(GetTicks(), connection));
118117
}
119118
}
120119
}
@@ -125,7 +124,7 @@ public void CleanupPool()
125124
{
126125
CheckDisposedImpl();
127126

128-
var now = DateTimeOffset.UtcNow;
127+
var now = GetTicks();
129128
var available = _available.ToArray();
130129
if (available.Count() <= _connectionString.MinPoolSize)
131130
return;
@@ -160,11 +159,17 @@ static FbConnectionInternal CreateNewConnection(FbConnectionString connectionStr
160159
return result;
161160
}
162161

163-
static bool IsAlive(long connectionLifeTime, DateTimeOffset created, DateTimeOffset now)
162+
static bool IsAlive(long connectionLifeTime, long created, long now)
164163
{
165164
if (connectionLifeTime == 0)
166165
return true;
167-
return created.AddSeconds(connectionLifeTime) > now;
166+
return (now - created) > (connectionLifeTime * 1000);
167+
}
168+
169+
static long GetTicks()
170+
{
171+
var ticks = Environment.TickCount;
172+
return ticks + -(long)int.MinValue;
168173
}
169174

170175
void CleanConnectionsImpl()

0 commit comments

Comments
 (0)