[#1000575] Timeout while getting a connection from pool

View Trackers | Bugs | Download .csv | Monitor

2006-03-01 00:23
Submitted by:
Assigned to:
Nobody (None)
Npgsql Version:
Timeout while getting a connection from pool

Detailed description
Under load Npgsql returns the following error.

Error Type:System.Exception
Error Message:Timeout while getting a connection from pool.
Stack Trace: at Npgsql.NpgsqlConnectorPool.RequestPooledConnector(NpgsqlConnection Connection)
at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection Connection)
at Npgsql.NpgsqlConnection.Open()
at GetAws.OrderDB.ReadSearchRememeber(String User)
at GetAws.OrderDB.SearchRemember(String User, String Url)
at GetAws.SiteAdmin.AwsOrderManager.Search_Click(Object sender, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain()

Once this error occurs all subsequent requests result in the same error until the application pool is cleared of IIS is restarted.

I can connect to the postgres server and restarting postgres has no effect.


Date: 2014-07-22 07:42
Sender: Đani Mehić

Hi, we have same situation in our production software, we use it in async socket server. Problem is not related only to pooled connections but non pooled also. Version of Npgsql.Net that we use is 2.0.7. I did debugging with WinDBG, and we got to point that blocking part of code is NpgsqlClosedState.cs Open method.

IAsyncResult result = socket.BeginConnect(ep, null, null);

if (!result.AsyncWaitHandle.WaitOne(context.ConnectionTimeout*1000, true))
throw new Exception(resman.GetString("Exception_ConnectionTimeout"));


At moment when problem occurs connection waits on AsyncWaitHandle, and for some reason it can't open connection to DB. At same moment it is possible to establish connection to DB with PgAdmin, telnet to it etc, so it is not network or DB issue.
In WinDBG, I noticed that IO Completion Port Thread Pool is at max at that moment (our server tries to connect on same thread that it received it's async read callback), and it looks like new calls as BeginConnect is in code above are blocked for some time.

After detecting this issue, I tried to switch call in mentioned file to use sync socket Connect method, and problem dissapeared. Code snippet mentioned above was changed to:


Of course this isn't really good solution, because we no longer have control on timeout, so our final fix that we are testing at the moment was to use Taks that is scheduled on regular thread pool which also solved original issue. As we use .net 4.0 in our projects, we don't have problem with using Task as solution, code that we are testing at the moment looks like this:

int timeout = context.ConnectionTimeout * 1000;
Task task = Task.Factory.StartNew( () => socket.Connect(ep));
Task.WaitAny(new Task[] { task }, timeout);

It solves original issue, we are testing if there are any side effects, hope this will help somebody.
Date: 2012-04-05 12:49
Sender: Jochen Wezel

I used a connection string like
SERVER=mydbserver;MINPOOLSIZE=3;MaxPoolSize=15;ConnectionLifeTime=7;DATABASE=Test DB;UID=user;PWD=pass

but it didn't worked for me using npgsql v2.0.11.92
Date: 2009-08-26 16:52
Sender: Ron Leisti

Using Npgsql for the first time, I experienced this same error. I was able to resolve this simply by specifying a minimum connection pool size in the connection string (I also happened to specify a maximum at the same time, and did not test to see if only specifying the minimum was sufficient).


Attached Files:


No Changes Have Been Made to This Item

Powered By FusionForge