Skip to content

Connection pool error handling? #453

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
hexacyanide opened this issue Apr 11, 2013 · 7 comments
Closed

Connection pool error handling? #453

hexacyanide opened this issue Apr 11, 2013 · 7 comments

Comments

@hexacyanide
Copy link

It appears I can't attach error handling to pools, so how are connection pool disconnects handled?

var pool = mysql.createPool();

//returns an error that says object "pool" has no method "on"
pool.on('error', function (err) {
  console.log(err);
});
@imkira
Copy link
Collaborator

imkira commented Apr 12, 2013

hexacyanide, I don't know if this is exactly what you need but:

pool.getConnection(function(err, connection) {
  if (err) {
    console.log(err);
    return;
  }
  connection.on('error', function(err) {
    console.log(err);
  });
  // do something with the connection...
});

Please note though that node-mysql already manages the connection cleanup itself, so you should not need to do that by yourself.

@hexacyanide
Copy link
Author

I would create a connection pool and come back a few days later to find a disconnect, although it hasn't happened since I installed the latest build. Not sure if it'll still happen, will report if it does.

@dresende
Copy link
Collaborator

Reopen if it does.

@apparatusdeus
Copy link

Hi hexacyanide,

It looks like you were/are having a similar problem to me. I've been creating a connection pool and coming back a few days later to find a disconnect (See #528) and while trying to resolve this problem. I attempted to add handlers onto created connections to give me more details about what was going on and ran into a problem when following the documentation where by I was receiving the error "TypeError: Object # has no method 'on'" when trying to add listeners to the on connect event of the pool. (See #533)

Did you manage to resolve your problem?

@hexacyanide
Copy link
Author

Yes, the problem ceased after I updated the module. Now, it automatically reconnects.

@BenScarberry
Copy link

@hexacyanide Can you please share your code for this part, cause I have the same problem?

@dougwilson
Copy link
Member

@BenScarberry, the issue @hexacyanide was having was doing pool.on('error', ... and getting the error TypeError: Object # has no method 'on'. This was solved without adding code, it was simply caused by using a version of the module where pool hadn't become an event emitter. The solution was to update the module...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants