SCM

[#1010978] ClearAllPools leaking connections

View Trackers | Patches | Download .csv | Monitor

Date:
2011-01-24 20:12
Priority:
3
State:
Open
Submitted by:
Randon Spackman (rspackman)
Assigned to:
Nobody (None)
Category:
Group:
Resolution:
None
 
Summary:
ClearAllPools leaking connections

Detailed description
The behavior of NpgsqlConnection's ClearAllPools is slightly different that OracleConnection's and SQLConnection's. SQLConnection's docs specify that connections in use at the time of ClearAllPools will be closed as soon as the connection is closed. (See http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.clearallpools.aspx) Instead, any connections in use will have one of two behaviors:

1) If no new connection queue is established between the ClearAllPools call and the Connection.Close, the connection will be lost until garbage collection.

2) If a new connection queue is established between the calls, the connection is returned to that queue.

The following code will demonstrate the problems:

namespace DALTest
{
class DALTestClass
{
static void Test1()
{
// Problem: A connection in use at the time of ClearAllPools is never released from Postgres (SELECT * FROM pg_stat_activity;)
var Conn = new Npgsql.NpgsqlConnection("Database=test;User Id=test;Password=test;Server=localhost;Port=5432");
Conn.Open();
Npgsql.NpgsqlConnection.ClearAllPools();
Conn.Dispose();
Npgsql.NpgsqlConnection.ClearAllPools(); // Fails to remove existing connection; it is not in pool and is leaked
}

static void Test2()
{
// Problem: A connection in use at the time of ClearAllPools is re-added to the pool
var Conn = new Npgsql.NpgsqlConnection("Database=test;User Id=test;Password=test;Server=localhost;Port=5432");
Conn.Open();
Npgsql.NpgsqlConnection.ClearAllPools();

var Conn2 = new Npgsql.NpgsqlConnection("Database=test;User Id=test;Password=test;Server=localhost;Port=5432");
Conn2.Open();
Conn2.Dispose();

Conn.Dispose(); // Adds connection back to pool
Npgsql.NpgsqlConnection.ClearAllPools(); // Releases both connections
}

static int Main()
{
Test1();
Test2();
return 0;
}
}
}

Followup

No Followups Have Been Posted

Attached Files:

Attachments:
NpgsqlConnectorPool.cs.patch.txt

Changes:

Field Old Value Date By
File Added587: NpgsqlConnectorPool.cs.patch.txt2011-01-24 20:12rspackman
Powered By FusionForge