{"action":"opened","issue":{"url":"https://api.github.com/repos/raix/push/issues/229","repository_url":"https://api.github.com/repos/raix/push","labels_url":"https://api.github.com/repos/raix/push/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/raix/push/issues/229/comments","events_url":"https://api.github.com/repos/raix/push/issues/229/events","html_url":"https://github.com/raix/push/issues/229","id":166328131,"number":229,"title":"Unhandled exception when connection times out","user":{"login":"flaviogrossi","id":879129,"avatar_url":"https://avatars.githubusercontent.com/u/879129?v=3","gravatar_id":"","url":"https://api.github.com/users/flaviogrossi","html_url":"https://github.com/flaviogrossi","followers_url":"https://api.github.com/users/flaviogrossi/followers","following_url":"https://api.github.com/users/flaviogrossi/following{/other_user}","gists_url":"https://api.github.com/users/flaviogrossi/gists{/gist_id}","starred_url":"https://api.github.com/users/flaviogrossi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flaviogrossi/subscriptions","organizations_url":"https://api.github.com/users/flaviogrossi/orgs","repos_url":"https://api.github.com/users/flaviogrossi/repos","events_url":"https://api.github.com/users/flaviogrossi/events{/privacy}","received_events_url":"https://api.github.com/users/flaviogrossi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-07-19T13:15:03Z","updated_at":"2016-07-19T13:15:03Z","closed_at":null,"body":"I noticed that an unhandled exception is raised when a connection to an APN is started (to send notifications to apple devices) but the connection times out. The following error is raised:\r\n\r\n```\r\nthrow e;\r\n      ^\r\nError: Connect timed out\r\n    at Connection.<anonymous> (/home/flavio/.meteor/packages/raix_push/.3.0.2.1ojwzxu++os+web.browser+web.cordova/npm/node_modules/apn/lib/connection.js:193:36)                                            \r\n    at Timer.listOnTimeout [as ontimeout] (timers.js:121:15)\r\n```\r\n\r\nand then the whole application crashes.\r\n\r\nA quick way to reproduce this is to drop all tcp connections to outbound port 2195 via iptables on the test machine and then trying to send a notification to an apple device.\r\n\r\nAs a workaround i found that adding an event listener for the `error` event correctly fixes the problem. I'm talking about adding [here](https://github.com/raix/push/blob/8f54dbfae705584a621defc91e1c8dbf9f9a41b1/lib/server/push.api.js#L126) the following code:\r\n\r\n```\r\napnConnection.on('error', function (err) {\r\n    console.log('got error: ', err);\r\n    // maybe some cleanup code here?\r\n});\r\n```\r\n\r\njust like it is done for the `transmissionError` two lines below in the very same file.\r\n\r\nWhat do you think?\r\n"}}
{"actor":{"display_login":"flaviogrossi"}}