Issue Details (XML | Word | Printable)

Key: DNET-607
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Jiri Cincura
Reporter: Simon Carter
Votes: 0
Watchers: 1

If you were logged in you would be able to see more operations.
.NET Data provider

Pooling clears current active connections

Created: 20/May/15 04:21 PM   Updated: 23/Jul/15 11:37 AM
Component/s: ADO.NET Provider
Affects Version/s:
Fix Version/s:

Windows 8
Visual Studio Pro 2013
Firebird 2.5.2

 Description  « Hide
The following method within FbConnectionPoolManager.cs

public void CleanupPool()
lock (_syncRoot)
var now = DateTimeOffset.UtcNow;
var available = _available.ToArray();
var keep = available.Where(x => IsAlive(_connectionString.ConnectionLifeTime, x.Created, now)).ToArray();

var keepCount = keep.Count();

if (keepCount < _connectionString.MinPoolSize)
keep = available.Except(keep).Take(_connectionString.MinPoolSize - keepCount).ToArray();

var release = available.Except(keep).ToArray();
release.AsParallel().ForAll(x => x.Dispose());
_available = new Queue<Item>(keep);

The line keep = available.Except(keep).Take(_connectionString.MinPoolSize - keepCount).ToArray(); will always clear existing connections when the number of connections is less than the Minimum Pool Size.

By removing the following lines, all works as expected:

var keepCount = keep.Count();

if (keepCount < _connectionString.MinPoolSize)
keep = available.Except(keep).Take(_connectionString.MinPoolSize - keepCount).ToArray();

Also the Take(_connectionString.MinPoolSize - keepCount) only takes account of the min pool size and not the maximum, so "other" connections above min pool size could also be lost at this point

The following is my connection string:

User=USERNAME;Password=password;Database=DBName.fdb;DataSource=;Dialect=3;MinPoolSize=20;MaxPoolSize=150;Pooling=True;Connection lifetime=0;Packet Size=8192;CharSet=UTF8

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jiri Cincura added a comment - 06/Jul/15 01:20 PM