{"action":"opened","issue":{"url":"https://api.github.com/repos/brianc/node-pg-cursor/issues/10","labels_url":"https://api.github.com/repos/brianc/node-pg-cursor/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/brianc/node-pg-cursor/issues/10/comments","events_url":"https://api.github.com/repos/brianc/node-pg-cursor/issues/10/events","html_url":"https://github.com/brianc/node-pg-cursor/issues/10","id":59842985,"number":10,"title":"Error Handling","user":{"login":"Digicrat","id":1891060,"avatar_url":"https://avatars.githubusercontent.com/u/1891060?v=3","gravatar_id":"","url":"https://api.github.com/users/Digicrat","html_url":"https://github.com/Digicrat","followers_url":"https://api.github.com/users/Digicrat/followers","following_url":"https://api.github.com/users/Digicrat/following{/other_user}","gists_url":"https://api.github.com/users/Digicrat/gists{/gist_id}","starred_url":"https://api.github.com/users/Digicrat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Digicrat/subscriptions","organizations_url":"https://api.github.com/users/Digicrat/orgs","repos_url":"https://api.github.com/users/Digicrat/repos","events_url":"https://api.github.com/users/Digicrat/events{/privacy}","received_events_url":"https://api.github.com/users/Digicrat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-03-04T18:53:23Z","updated_at":"2015-03-04T18:53:23Z","closed_at":null,"body":"I could be doing something wrong in my error handling, but it appears that pg-cursor doesn't behave nicely if there's an error with the initial query.  Specifically, the connection is not freed immediately, or at all.  See demo below.\r\n\r\nIn this particular case it would actually be useful to obtain the error immediately, without waiting for a cursor.read() call.  For example, a callback parameter to the Cursor constructor (or the query call) that is called when we know the status of the query, without retrieving any rows.\r\n\r\n```javascript\r\nvar pg = require('pg');\r\nvar Cursor = require('pg-cursor');\r\nvar conString = \"postgres://username:password@localhost/database\";\r\n\r\npg.connect(conString, function(err, client, done) {\r\n    if (err) {\r\n        return console.error('error fetching client from pool', err);\r\n    }\r\n\r\n    var cursor = client.query(new Cursor('SELECT * FROM invalid')); // This query is invalid\r\n    cursor.read(10, function(err, rows) {\r\n        if (err) {\r\n            console.log(\"Found an error\"); // Base Test (never exits)\r\n       /* // ALT Test: If I call done() instead of cursor.close() the script will exit, but only after a 30-second delay (some sort of timeout I'd assume).\r\n            console.log(\"Found an error, calling done()\");\r\n            done();\r\n            return;\r\n        */\r\n        } else {\r\n            console.log(\"No error\");\r\n        }\r\n        // If we reach this point with a cursor.read err, cursor.close's callback will never be called and the script will not exit\r\n        cursor.close(function(err) {\r\n            if (err) {\r\n                console.log(\"Close Error\");\r\n            } else {\r\n                console.log(\"Close Succeeded, calling done\");\r\n                done();\r\n            }\r\n        });\r\n    });\r\n\r\n});\r\n```"}}