{"action":"created","issue":{"url":"https://api.github.com/repos/request/request/issues/2161","repository_url":"https://api.github.com/repos/request/request","labels_url":"https://api.github.com/repos/request/request/issues/2161/labels{/name}","comments_url":"https://api.github.com/repos/request/request/issues/2161/comments","events_url":"https://api.github.com/repos/request/request/issues/2161/events","html_url":"https://github.com/request/request/issues/2161","id":147161315,"number":2161,"title":"Can't catch error using callback and on-error handler","user":{"login":"bushev","id":7535766,"avatar_url":"https://avatars.githubusercontent.com/u/7535766?v=3","gravatar_id":"","url":"https://api.github.com/users/bushev","html_url":"https://github.com/bushev","followers_url":"https://api.github.com/users/bushev/followers","following_url":"https://api.github.com/users/bushev/following{/other_user}","gists_url":"https://api.github.com/users/bushev/gists{/gist_id}","starred_url":"https://api.github.com/users/bushev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bushev/subscriptions","organizations_url":"https://api.github.com/users/bushev/orgs","repos_url":"https://api.github.com/users/bushev/repos","events_url":"https://api.github.com/users/bushev/events{/privacy}","received_events_url":"https://api.github.com/users/bushev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/request/request/labels/Not%20enough%20info%20(see%20CONTRIBUTING.md)","name":"Not enough info (see CONTRIBUTING.md)","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-04-09T20:35:56Z","updated_at":"2016-09-02T16:10:21Z","closed_at":"2016-06-17T11:47:46Z","body":"Hello, I can't handle error in the following code:\r\n\r\n```javascript\r\n        this.request.get({\r\n            url: url,\r\n            headers: this.headers\r\n        }, (err, res, body) => {\r\n            if (err) return callback(err);\r\n\r\n            callback(err, res, body);\r\n        }).on('error', err => {\r\n            console.log(err.stack);\r\n            callback(err);\r\n        });\r\n```\r\n\r\nI got error output:\r\n```\r\nError: read ECONNRESET\r\n    at exports._errnoException (util.js:856:11)\r\n    at TCP.onread (net.js:550:26)\r\n```\r\n\r\nAfter this my process terminates."},"comment":{"url":"https://api.github.com/repos/request/request/issues/comments/244418664","html_url":"https://github.com/request/request/issues/2161#issuecomment-244418664","issue_url":"https://api.github.com/repos/request/request/issues/2161","id":244418664,"user":{"login":"josser","id":103639,"avatar_url":"https://avatars.githubusercontent.com/u/103639?v=3","gravatar_id":"","url":"https://api.github.com/users/josser","html_url":"https://github.com/josser","followers_url":"https://api.github.com/users/josser/followers","following_url":"https://api.github.com/users/josser/following{/other_user}","gists_url":"https://api.github.com/users/josser/gists{/gist_id}","starred_url":"https://api.github.com/users/josser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josser/subscriptions","organizations_url":"https://api.github.com/users/josser/orgs","repos_url":"https://api.github.com/users/josser/repos","events_url":"https://api.github.com/users/josser/events{/privacy}","received_events_url":"https://api.github.com/users/josser/received_events","type":"User","site_admin":false},"created_at":"2016-09-02T16:10:21Z","updated_at":"2016-09-02T16:10:21Z","body":"We have same issue with just the same code: \r\n\r\n```javascript\r\nlet reqObj;\r\n\r\ntry {\r\n reqObj = request(options, (err, res) => {\r\n   if (err) {\r\n     console.log('got in callback', err);\r\n   }\r\n   console.log(res);\r\n }).on('error', err => {\r\n   console.log('got in error event', err);\r\n   reqObj.abort();\r\n });\r\n} catch (e) {\r\n console.log('Catched', e);\r\n reqObj.abort();\r\n}\r\n```\r\n\r\nWhen this code is executed in environments with bad connections it may cause unhadeledException. \r\n```javasctipt\r\n { Error: read ECONNRESET\r\n   at exports._errnoException (util.js:953:11)\r\n   at TCP.onread (net.js:563:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }\r\n```\r\nThis exception It not catched by catch() or .on('error'), or callback. The only way to handle such error is using process.on('uncacughtException') which is obviously not good practice.  \r\n\r\nI think issue is somewhere deeper in node.http module in some async function, because the only way to handle it is process.on('uncacughtException')\r\nBut I don't have enough knowledge to investigate this. \r\nThe most hard part in investigation is in nature of the issue: it's very hard to simulate such circumstances to reproduce it.  \r\nThank you and sorry for bad english"}}
{"actor":{"display_login":"josser"}}