{"action":"created","issue":{"url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/6","labels_url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/6/comments","events_url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/6/events","html_url":"https://github.com/coderhaoxin/pg-then/issues/6","id":110951637,"number":6,"title":"It randomly gets stuck","user":{"login":"nickretallack","id":13291,"avatar_url":"https://avatars.githubusercontent.com/u/13291?v=3","gravatar_id":"","url":"https://api.github.com/users/nickretallack","html_url":"https://github.com/nickretallack","followers_url":"https://api.github.com/users/nickretallack/followers","following_url":"https://api.github.com/users/nickretallack/following{/other_user}","gists_url":"https://api.github.com/users/nickretallack/gists{/gist_id}","starred_url":"https://api.github.com/users/nickretallack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickretallack/subscriptions","organizations_url":"https://api.github.com/users/nickretallack/orgs","repos_url":"https://api.github.com/users/nickretallack/repos","events_url":"https://api.github.com/users/nickretallack/events{/privacy}","received_events_url":"https://api.github.com/users/nickretallack/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-12T10:49:48Z","updated_at":"2015-11-06T09:33:07Z","closed_at":null,"body":"If I use this library for a while, it has a chance of getting stuck in a query and never returning.  Once this has happened, all future queries get stuck too.  This behavior is consistent with node-postgres' description of what happens when you leak connections from a pool.\r\n\r\nHere is a program that demonstrates the problem.  It should be able to continue doing queries forever, but instead it gets stuck around try 18320 to 28906.\r\n\r\n```javascript\r\nvar pg = require('pg-then');\r\nvar database_uri = 'postgresql://localhost:5432/test'\r\nvar pool = pg.Pool(database_uri)\r\n\r\nvar count = 0;\r\nfunction test_forever() {\r\n\tcount += 1;\r\n\tconsole.log(\"try\", count)\r\n\tif (count > 100000) {\r\n\t\tconsole.log(\"success\");\r\n\t\treturn;\r\n\tpool.query('select 1 from pg_stat_activity').then(test_forever);\r\n}\r\n\r\ntest_forever();\r\n```\r\n\r\nHere's the same thing the way node-postgres recommends you write it.  It continues forever:\r\n\r\n```javascript\r\nvar pg = require('pg');\r\nvar database_uri = 'postgresql://localhost:5432/test'\r\n\r\nvar count = 0;\r\nfunction test_forever() {\r\n\tcount += 1;\r\n\tconsole.log(\"try\", count)\r\n\tif (count >= 100000) {\r\n\t\tconsole.log(\"Success!\")\r\n\t\treturn;\r\n\t}\r\n\r\n\tpg.connect(database_uri, function(err, client, done) {\r\n\t\tvar handleError = function(err) {\r\n\t\t\tif(!err) return false;\r\n\t\t\tif(client){\r\n\t\t\t\tdone(client);\r\n\t\t\t}\r\n\t\t\treturn true;\r\n\t\t};\r\n\t\tif(handleError(err)) return;\r\n\r\n\t\tclient.query('select 1 from pg_stat_activity', function(err, result) {\r\n\t\t\tif(handleError(err)) return;\r\n\t\t\tdone();\r\n\t\t\ttest_forever();\r\n\t\t})\r\n\t})\r\n}\r\n\r\ntest_forever();\r\n```"},"comment":{"url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/comments/154359588","html_url":"https://github.com/coderhaoxin/pg-then/issues/6#issuecomment-154359588","issue_url":"https://api.github.com/repos/coderhaoxin/pg-then/issues/6","id":154359588,"user":{"login":"amxfonseca","id":6478355,"avatar_url":"https://avatars.githubusercontent.com/u/6478355?v=3","gravatar_id":"","url":"https://api.github.com/users/amxfonseca","html_url":"https://github.com/amxfonseca","followers_url":"https://api.github.com/users/amxfonseca/followers","following_url":"https://api.github.com/users/amxfonseca/following{/other_user}","gists_url":"https://api.github.com/users/amxfonseca/gists{/gist_id}","starred_url":"https://api.github.com/users/amxfonseca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amxfonseca/subscriptions","organizations_url":"https://api.github.com/users/amxfonseca/orgs","repos_url":"https://api.github.com/users/amxfonseca/repos","events_url":"https://api.github.com/users/amxfonseca/events{/privacy}","received_events_url":"https://api.github.com/users/amxfonseca/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T09:33:06Z","updated_at":"2015-11-06T09:33:06Z","body":"I'm also getting the same behavior. After 10 or so queries the system get's stuck. I jus't started to use this library yesterday, I didn't had the time to debug it yet. I will try to check it soon."}}