{"action":"created","issue":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/1348","repository_url":"https://api.github.com/repos/npgsql/npgsql","labels_url":"https://api.github.com/repos/npgsql/npgsql/issues/1348/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/npgsql/issues/1348/comments","events_url":"https://api.github.com/repos/npgsql/npgsql/issues/1348/events","html_url":"https://github.com/npgsql/npgsql/issues/1348","id":186905346,"number":1348,"title":"Connection Pool has been Exhausted but not on Server","user":{"login":"bradyclifford","id":8923247,"avatar_url":"https://avatars.githubusercontent.com/u/8923247?v=3","gravatar_id":"","url":"https://api.github.com/users/bradyclifford","html_url":"https://github.com/bradyclifford","followers_url":"https://api.github.com/users/bradyclifford/followers","following_url":"https://api.github.com/users/bradyclifford/following{/other_user}","gists_url":"https://api.github.com/users/bradyclifford/gists{/gist_id}","starred_url":"https://api.github.com/users/bradyclifford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradyclifford/subscriptions","organizations_url":"https://api.github.com/users/bradyclifford/orgs","repos_url":"https://api.github.com/users/bradyclifford/repos","events_url":"https://api.github.com/users/bradyclifford/events{/privacy}","received_events_url":"https://api.github.com/users/bradyclifford/received_events","type":"User","site_admin":false},"labels":[{"id":370339838,"url":"https://api.github.com/repos/npgsql/npgsql/labels/invalid","name":"invalid","color":"fbca04","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2016-11-02T20:03:04Z","updated_at":"2016-11-15T08:32:32Z","closed_at":"2016-11-14T16:31:09Z","body":"We have been experience connection issues with Postgres more and more as our load increases.  We first were getting:\r\n```\r\nnpgsql.NpgsqlException (0x80004005): Exception while writing to stream ---> \r\nSystem.IO.IOException: Unable to write data to the transport connection: \r\nAn existing connection was forcibly closed by the remote host. ---> \r\nSystem.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host\r\n```\r\n\r\nWe realized that our F5 was terminating connections after 5 minutes.  So we added `Keepalive=260` to our connection string.\r\n\r\nThat got rid of that error until we started to max out our 100 default connections on the server. We kept upping the max connections.  We realized that the connections would gradually go up and up and never recycle. It would raise to 900 in just under an hour.  It forced us to kill idle connections being kept open by the Keepalive on the Postgres server manually.  \r\n\r\nWe then swapped out `Keepalive=260` with `Connection Idle Lifetime=260`.  We finally saw the connections recycle and keep at a steady threshold below 100.\r\n\r\nNow we are with the error below.  When we get this error, there are only 5-10 connections open on the Postgres server.  We haven't maxed out the pool size on the server.  Not sure why npgsql would think we have maxed it out on the client side.  Our current stopgap is to restart our app pool...  4 hours later, this error creeps up.\r\n\r\nHow would you suggest we debug this?  \r\n* Does Npgsql not recycling the connections at the same rate the server is?\r\n* Is there a way we can see how many connections Npgsql thinks are open?\r\n* Or do you think this is an actual `Timeout` issue? Maybe increasing our `Timeout` would help us identify the problem.\r\n\r\n```\r\nNpgsql.NpgsqlException (0x80004005): The connection pool has been exhausted, either raise MaxPoolSize (currently 100) or Timeout (currently 15 seconds)\r\n   at Npgsql.ConnectorPool.WaitForTask(Task task, TimeSpan timeout)\r\n   at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)\r\n   at Npgsql.NpgsqlConnection.OpenInternal()\r\n   at Npgsql.NpgsqlConnection.Open()\r\n```"},"comment":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/comments/260578890","html_url":"https://github.com/npgsql/npgsql/issues/1348#issuecomment-260578890","issue_url":"https://api.github.com/repos/npgsql/npgsql/issues/1348","id":260578890,"user":{"login":"roji","id":1862641,"avatar_url":"https://avatars.githubusercontent.com/u/1862641?v=3","gravatar_id":"","url":"https://api.github.com/users/roji","html_url":"https://github.com/roji","followers_url":"https://api.github.com/users/roji/followers","following_url":"https://api.github.com/users/roji/following{/other_user}","gists_url":"https://api.github.com/users/roji/gists{/gist_id}","starred_url":"https://api.github.com/users/roji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roji/subscriptions","organizations_url":"https://api.github.com/users/roji/orgs","repos_url":"https://api.github.com/users/roji/repos","events_url":"https://api.github.com/users/roji/events{/privacy}","received_events_url":"https://api.github.com/users/roji/received_events","type":"User","site_admin":false},"created_at":"2016-11-15T08:32:32Z","updated_at":"2016-11-15T08:32:32Z","body":"@bradyclifford thanks for letting me know. 3.2 will include some features which will hopefully help track this kind of thing down."}}
{"actor":{"display_login":"roji"}}