{"action":"created","issue":{"url":"https://api.github.com/repos/mysqljs/mysql/issues/1515","repository_url":"https://api.github.com/repos/mysqljs/mysql","labels_url":"https://api.github.com/repos/mysqljs/mysql/issues/1515/labels{/name}","comments_url":"https://api.github.com/repos/mysqljs/mysql/issues/1515/comments","events_url":"https://api.github.com/repos/mysqljs/mysql/issues/1515/events","html_url":"https://github.com/mysqljs/mysql/issues/1515","id":175200094,"number":1515,"title":"unexpected error when idle","user":{"login":"superhero","id":839818,"avatar_url":"https://avatars.githubusercontent.com/u/839818?v=3","gravatar_id":"","url":"https://api.github.com/users/superhero","html_url":"https://github.com/superhero","followers_url":"https://api.github.com/users/superhero/followers","following_url":"https://api.github.com/users/superhero/following{/other_user}","gists_url":"https://api.github.com/users/superhero/gists{/gist_id}","starred_url":"https://api.github.com/users/superhero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superhero/subscriptions","organizations_url":"https://api.github.com/users/superhero/orgs","repos_url":"https://api.github.com/users/superhero/repos","events_url":"https://api.github.com/users/superhero/events{/privacy}","received_events_url":"https://api.github.com/users/superhero/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mysqljs/mysql/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-06T09:24:29Z","updated_at":"2016-09-06T09:41:40Z","closed_at":null,"body":"Ran a long job, 8h in to it, it through an error... what I think is strange is that I only made 1 sql query. So I don't know if I misunderstood something, but to me that seems very strange that the mysql module would through an error at all. After the result has been returned I expected the mysql module to stay quite. How could I catch this exception?\r\n\r\n**`app/main`**\r\n```\r\nrequire('app/wrapper/mysql')((error, connection) => // see below for file content\r\n{\r\n  if (error)\r\n    throw error;\r\n\r\n  connection.query(query, (error, rows) =>\r\n  {\r\n    if (error)\r\n      throw error;\r\n\r\n    // bunch of logic, none mysql related, just looping through the result `rows`\r\n```\r\n\r\n**`app/wrapper/mysql`**\r\n```\r\n'use strict';\r\n\r\nconst connection = require('mysql').createConnection(\r\n{\r\n  host     : '...',\r\n  user     : '...',\r\n  password : '...',\r\n  database : '...'\r\n});\r\n\r\nmodule.exports = callback =>\r\n  connection.state == 'connected'\r\n  ? callback(null, connection)\r\n  : connection.connect(error => callback(error, connection));\r\n```\r\n\r\n**`output`**\r\n```\r\nevents.js:160\r\n      throw er; // Unhandled 'error' event\r\n      ^\r\n\r\nError: Connection lost: The server closed the connection.\r\n    at Protocol.end (/opt/bot/node_modules/mysql/lib/protocol/Protocol.js:109:13)\r\n    at Socket.<anonymous> (/opt/bot/node_modules/mysql/lib/Connection.js:115:28)\r\n    at emitNone (events.js:91:20)\r\n    at Socket.emit (events.js:185:7)\r\n    at endReadableNT (_stream_readable.js:926:12)\r\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\r\n    at process._tickCallback (internal/process/next_tick.js:98:9)\r\n\r\nnpm info lifecycle credit-limit-bot@1.0.0~start: Failed to exec start script\r\nnpm ERR! Linux 4.4.0-36-generic\r\nnpm ERR! argv \"/usr/local/bin/node\" \"/usr/local/bin/npm\" \"start\"\r\nnpm ERR! node v6.1.0\r\nnpm ERR! npm  v3.8.6\r\nnpm ERR! code ELIFECYCLE\r\nnpm ERR! credit-limit-bot@1.0.0 start: `npm install && npm update && node node_modules/app/main.js`\r\nnpm ERR! Exit status 1\r\nnpm ERR! \r\nnpm ERR! Failed at the credit-limit-bot@1.0.0 start script 'npm install && npm update && node node_modules/app/main.js'.\r\nnpm ERR! Make sure you have the latest version of node.js and npm installed.\r\nnpm ERR! If you do, this is most likely a problem with the credit-limit-bot package,\r\nnpm ERR! not with npm itself.\r\nnpm ERR! Tell the author that this fails on your system:\r\nnpm ERR!     npm install && npm update && node node_modules/app/main.js\r\nnpm ERR! You can get information on how to open an issue for this project with:\r\nnpm ERR!     npm bugs credit-limit-bot\r\nnpm ERR! Or if that isn't available, you can get their info via:\r\nnpm ERR!     npm owner ls credit-limit-bot\r\nnpm ERR! There is likely additional logging output above.\r\n```"},"comment":{"url":"https://api.github.com/repos/mysqljs/mysql/issues/comments/244901251","html_url":"https://github.com/mysqljs/mysql/issues/1515#issuecomment-244901251","issue_url":"https://api.github.com/repos/mysqljs/mysql/issues/1515","id":244901251,"user":{"login":"superhero","id":839818,"avatar_url":"https://avatars.githubusercontent.com/u/839818?v=3","gravatar_id":"","url":"https://api.github.com/users/superhero","html_url":"https://github.com/superhero","followers_url":"https://api.github.com/users/superhero/followers","following_url":"https://api.github.com/users/superhero/following{/other_user}","gists_url":"https://api.github.com/users/superhero/gists{/gist_id}","starred_url":"https://api.github.com/users/superhero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/superhero/subscriptions","organizations_url":"https://api.github.com/users/superhero/orgs","repos_url":"https://api.github.com/users/superhero/repos","events_url":"https://api.github.com/users/superhero/events{/privacy}","received_events_url":"https://api.github.com/users/superhero/received_events","type":"User","site_admin":false},"created_at":"2016-09-06T09:41:40Z","updated_at":"2016-09-06T09:41:40Z","body":"@sidorares ty for fast response. As you can see in my code, the rows are already returned. So I don't see why an exception is even disrupting the process. After a new query or connection is requested I would understand if there would be an exception though.\r\n\r\nTo prevent this behavior, if I understand you correctly, I could write re-write my wrapper like so?:\r\n\r\n```\r\n'use strict';\r\n\r\nconst connection = require('mysql').createConnection(\r\n{\r\n  host     : '...',\r\n  user     : '...',\r\n  password : '...',\r\n  database : '...'\r\n});\r\n\r\n// preventing system crash when the connection is droped\r\nconnection.on('error', error =>  console.log(error));\r\n\r\nmodule.exports = callback =>\r\n  connection.state == 'connected'\r\n  ? callback(null, connection)\r\n  : connection.connect(error => callback(error, connection));\r\n```"}}
{"actor":{"display_login":"superhero"}}