{"action":"closed","issue":{"url":"https://api.github.com/repos/npgsql/npgsql/issues/505","labels_url":"https://api.github.com/repos/npgsql/npgsql/issues/505/labels{/name}","comments_url":"https://api.github.com/repos/npgsql/npgsql/issues/505/comments","events_url":"https://api.github.com/repos/npgsql/npgsql/issues/505/events","html_url":"https://github.com/npgsql/npgsql/issues/505","id":59127626,"number":505,"title":"Command never gets garbage allocated if not disposed","user":{"login":"havard","id":45829,"avatar_url":"https://avatars.githubusercontent.com/u/45829?v=3","gravatar_id":"","url":"https://api.github.com/users/havard","html_url":"https://github.com/havard","followers_url":"https://api.github.com/users/havard/followers","following_url":"https://api.github.com/users/havard/following{/other_user}","gists_url":"https://api.github.com/users/havard/gists{/gist_id}","starred_url":"https://api.github.com/users/havard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/havard/subscriptions","organizations_url":"https://api.github.com/users/havard/orgs","repos_url":"https://api.github.com/users/havard/repos","events_url":"https://api.github.com/users/havard/events{/privacy}","received_events_url":"https://api.github.com/users/havard/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/npgsql/npgsql/labels/bug","name":"bug","color":"e11d21"},{"url":"https://api.github.com/repos/npgsql/npgsql/labels/critical","name":"critical","color":"e11d21"}],"state":"closed","locked":false,"assignee":{"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},"milestone":{"url":"https://api.github.com/repos/npgsql/npgsql/milestones/8","html_url":"https://github.com/npgsql/npgsql/milestones/2.2.5","labels_url":"https://api.github.com/repos/npgsql/npgsql/milestones/8/labels","id":967745,"number":8,"title":"2.2.5","description":"","creator":{"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},"open_issues":1,"closed_issues":3,"state":"open","created_at":"2015-02-05T21:14:16Z","updated_at":"2015-03-02T03:48:49Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2015-02-26T19:24:37Z","updated_at":"2015-03-02T03:48:49Z","closed_at":"2015-03-02T03:48:49Z","body":"I have a scenario where a process runs in Azure for a long time, querying a database rather eagerly. I estimate the load to be 5-20 queries/second.\r\n\r\n### The issue \r\nAfter running for about 4 hours, the job consistently fails to connect to the database. The relevant exception and stack trace is given below:\r\n\r\n    An exception of type Npgsql.NpgsqlException was thrown: Failed to establish a connection to 'database-host'. \r\n    Stack trace: \r\n      at Npgsql.NpgsqlClosedState.Open(NpgsqlConnector context, Int32 timeout)\r\n      at Npgsql.NpgsqlConnector.Open()\r\n      at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection) \r\n      at Npgsql.NpgsqlConnectorPool.RequestPooledConnectorInternal(NpgsqlConnection Connection) \r\n      at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection Connection) \r\n      at Npgsql.NpgsqlConnection.Open() at System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken) \r\n      --- End of stack trace from previous location where exception was thrown --- \r\n      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) \r\n      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) \r\n      at System.Data.Entity.Core.EntityClient.EntityConnection.d__8.MoveNext() \r\n\r\n    Inner exceptions: \r\n      An exception of type System.Net.Sockets.SocketException was thrown: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full \r\n      Stack trace: \r\n        at Npgsql.NpgsqlClosedState.Open(NpgsqlConnector context, Int32 timeout)\r\n\r\n### Possible causes\r\nI have not identified a certain cause, but judging by [this MSDN blog post](http://blogs.msdn.com/b/sql_protocols/archive/2009/03/09/understanding-the-error-an-operation-on-a-socket-could-not-be-performed-because-the-system-lacked-sufficient-buffer-space-or-because-a-queue-was-full.aspx) it seems that Npgsql either exhausts TCP ephemeral ports or the memory available for TCP buffers.\r\n\r\n### Reproducing the issue\r\nSadly, I am unable to share any code. The essence is an EF6 DBContext, connected with pooling enabled (I also use SSL, if that matters), hitting the database eagerly for an extended time period. Eventually, an Open should fail with the error above. The same single instance of the DBContext is used, and async/await is used rather heavily."}}