Skip to content

Pool connection failure doesn't emit error event #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
topia opened this issue Nov 6, 2014 · 6 comments
Closed

Pool connection failure doesn't emit error event #941

topia opened this issue Nov 6, 2014 · 6 comments
Labels

Comments

@topia
Copy link

topia commented Nov 6, 2014

Pool.query doesn't emit error event, when it failed with connection error.

index.js

var mysql = require('mysql');

var pool = mysql.createPool({host: 'unknown-host', port: 3306, user: 'test', password: 'test', database: 'test'});
var query;

query = pool.query('SELECT 1');
query.on('error', function (err) { console.log("error emitted", err); })

query = pool.query('SELECT 1', function (err) { console.log("error callbacked", err); });

query = pool.query('SELECT 1', function (err) { console.log("error callbacked, but bad style", err); });
query.on('error', function (err) { console.log("error emitted", err); })

package.json

{
  "name": "mysql-bug-temp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "mysql": "^2.5.2"
  }
}

expected

error emitted { [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }
error callbacked { [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }
error callbacked, but bad style { [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }

actual

error callbacked { [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }
error callbacked, but bad style { [Error: getaddrinfo ENOTFOUND]
  code: 'ENOTFOUND',
  errno: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  fatal: true }
@topia
Copy link
Author

topia commented Nov 6, 2014

I think it will be fixed with use query.end(err); on https://github.com/felixge/node-mysql/blob/master/lib/Pool.js#L185

@dougwilson dougwilson added the bug label Nov 6, 2014
@dougwilson
Copy link
Member

Ah, I see what you're saying: the connection error is only propagated to the returned query if you are using the callback interface. This is a bug indeed.

@topia
Copy link
Author

topia commented Nov 6, 2014

I'm sorry to less description. I want to clarification:
connection error is only propagated to the specified callback function, but I want to use streaming (event) interface.
according to docs, I cannot specify callback on streaming interface, so I cannot catch connection error.

@dougwilson
Copy link
Member

Right, I understood what you were asking, @topia :) The answer is that it's a bug and I have to fix it :)

@topia
Copy link
Author

topia commented Nov 6, 2014

Thank you very match for fixing this!
🎉

@dougwilson
Copy link
Member

No problem! I just published it to npm as 2.5.3 :)

seangarner pushed a commit to seangarner/node-mysql that referenced this issue May 11, 2015
dveeden pushed a commit to dveeden/mysql that referenced this issue Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants