{"action":"created","issue":{"url":"https://api.github.com/repos/mauricio/postgresql-async/issues/132","labels_url":"https://api.github.com/repos/mauricio/postgresql-async/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/mauricio/postgresql-async/issues/132/comments","events_url":"https://api.github.com/repos/mauricio/postgresql-async/issues/132/events","html_url":"https://github.com/mauricio/postgresql-async/issues/132","id":57350337,"number":132,"title":"0.2.16 throwing ClosedChannelException","user":{"login":"dylex","id":106587,"avatar_url":"https://avatars.githubusercontent.com/u/106587?v=3","gravatar_id":"","url":"https://api.github.com/users/dylex","html_url":"https://github.com/dylex","followers_url":"https://api.github.com/users/dylex/followers","following_url":"https://api.github.com/users/dylex/following{/other_user}","gists_url":"https://api.github.com/users/dylex/gists{/gist_id}","starred_url":"https://api.github.com/users/dylex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dylex/subscriptions","organizations_url":"https://api.github.com/users/dylex/orgs","repos_url":"https://api.github.com/users/dylex/repos","events_url":"https://api.github.com/users/dylex/events{/privacy}","received_events_url":"https://api.github.com/users/dylex/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-11T17:43:24Z","updated_at":"2015-03-02T08:34:36Z","closed_at":null,"body":"It seems now that every single database error, even when it's explicitly caught and handled, ultimately results in a `ClosedChannelException`.  This seems to be a regression caused by https://github.com/mauricio/postgresql-async/commit/1f74c57a8f9c72822e34bedf45dedc5ae08001d5 since now the error thrown by `validate` via `giveBack` (because the connection was disconnected after the error response) is propagated, when it should not be.  I can provide some backtraces if necessary."},"comment":{"url":"https://api.github.com/repos/mauricio/postgresql-async/issues/comments/76674627","html_url":"https://github.com/mauricio/postgresql-async/issues/132#issuecomment-76674627","issue_url":"https://api.github.com/repos/mauricio/postgresql-async/issues/132","id":76674627,"user":{"login":"ivanyu","id":2189030,"avatar_url":"https://avatars.githubusercontent.com/u/2189030?v=3","gravatar_id":"","url":"https://api.github.com/users/ivanyu","html_url":"https://github.com/ivanyu","followers_url":"https://api.github.com/users/ivanyu/followers","following_url":"https://api.github.com/users/ivanyu/following{/other_user}","gists_url":"https://api.github.com/users/ivanyu/gists{/gist_id}","starred_url":"https://api.github.com/users/ivanyu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivanyu/subscriptions","organizations_url":"https://api.github.com/users/ivanyu/orgs","repos_url":"https://api.github.com/users/ivanyu/repos","events_url":"https://api.github.com/users/ivanyu/events{/privacy}","received_events_url":"https://api.github.com/users/ivanyu/received_events","type":"User","site_admin":false},"created_at":"2015-03-02T08:34:36Z","updated_at":"2015-03-02T08:34:36Z","body":"Hello there.\r\n\r\nI'm likely to have the similar trouble. I've looked into the code and believe that the problem is in possible multithread race in some places.\r\nFor instance, `SingleThreadedAsyncObjectPool`. Suppose we have an already created connection in the pool and two threads simultaneously call `createOrReturnItem`. It's not impossible for them to get the same single connection due to the lack of synchronization. Next, one of the threads uses the connection with failure and it gets closed. The other threads that owns the connection tries to send its query and gets `ClosedChannelException`.\r\nEven if the `SingleThreadedAsyncObjectPool` is used from a single thread, the problem remains since there is a tesing job (`testObjects`) done by timer (from another thread).\r\n\r\nLooking forward for your ideas. As I see it, the problem can be dealt with by adaptation of a concurrent data structure to store pooled connections."}}