views:

358

answers:

1

Background: I'm moving my application from npgsql v1 to npgsql v2.0.9. After a few minutes of running my application, I get a System.Exception: Timeout while getting a connection from the pool.

The web claims that this is due to leaking connections (opening a db connection, but not properly closing them).

So

I'm trying to diagnose leaking postgres connections in npgsql.

From the various web literature around; one way to diagnose leaking connections is to setup logging on npgsql, and look for the leaking connection warning message in the log. Problem is, I'm not seeing this message in the logs anywhere.

I also found utility that monitors npgsql connections, but it's unstable and crashes.

So I'm left manually inspecting code. For everyplace that creates an npgsql connection, there is a finally block disposing of it. For everyplace that opens a datareader, CommandBehavior.CloseConnection is used (and the datareader is disposed).

Any other places to check or can someone recommend a way to look for leaking pool connections?

+1  A: 

Hmmmm, this is very strange.... You should be getting some messages.

Those messages only appear when ms.net runtime finalizes the object though. Would it be possible that you are using more than default max connections at same time? I mean, your peak usage may be more than the 20 max number connections...

I hope it helps.

Please, let me know what do you get.

Francisco
Even if I crank up the connectons to 100, I still end up with this exception. I'm pretty positive we're not using that many connections.
Alan
Can you try disable connection pooling and check if you see connections floating in the server? You can disable pooling by adding Pooling=false in your connection string.If after using your app for a while you see connections in your pg server, you may be leaking connections. I hope it helps.
Francisco
Hi Francisco, Thanks for your help. I disabled pooling using Pooling=false as you suggested. In order to monitor connections I am using `SELECT * FROM pg_stat_activity` SQL query. The most connections I saw was 11, then it went back down to 1 (for the sql query) bouncing up to 3 or 4 and back down.As an aside, disabling pooling really slows down performance of npgsql/postgres.
Alan
Sorry for delay... This is really very strange that you are getting timeout from the pool. I have no idea about what can be happening in order to give you this error since after disabling connection pooling it seems to be closing the connections correctly.Do you think you can write a test sample where this problem appears?It would be very much helpful.Thanks in advance.
Francisco