felixge/node-mysql — Issue #142: driver stalls upon reconnect attempt that's immediately closed
Author: lloyd
Created: 2011-11-24 01:41:57+00:00
State: open

This problem is with `0.9.4` and node `0.4.11` OR node `0.6.2`

We're experiencing a specific issue when running `node-mysql` against a pool of database servers behind a zeus load balancer, though I think the logic problems in the code may be the cause of some other open issues.

Here's the precise behavior introduced by zeus that confuses the driver:

1. driver connects to mysql
2. connection dies and is shutdown (`FIN`, `ACK`)
3. driver attempts to reconnect
4. zeus accepts the connection and immediately closes it

Steps to reproduce:

1. point this script at your mysql instance: https://gist.github.com/1390350
2. while that thing is pinging every second, run this script: https://gist.github.com/1390405
3. ctrl-c the second script. notice that the first script is now hung. no connections are attempted.

There are a couple different approaches to fixing the problem, but the question is really how do you want the client to behave in this scenario? It could keep aggressively trying to reconnect in a tight loop, (each time zeus accepting and closing the connection), or it could emit an error. I think the error approach is maybe wisest, adding:

self.emit('error', 'reconnection attempt failed before connection was fully set up');

right here: https://github.com/felixge/node-mysql/blob/df94f9/lib/client.js#L68

If you feel like this is a sane approach, I'll gladly generate a patch and pull request. From our side we just want to get some sort of feedback from the driver that the connection is down and reconnection is failing.