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

Already on GitHub? Sign in to your account

Connection loss detection #11

zerodivisi0n opened this Issue May 29, 2011 · 7 comments


None yet
2 participants

Is there a way to detect loss of connection to the server? How about a use for this purpose event 'error' on Database object?

And also use option MYSQL_OPT_RECONNECT when executing queries to automatic reconnection.

@mariano mariano was assigned May 29, 2011


mariano commented May 29, 2011

Let me think about the loss detection for a bit.

Regarding the reconnect, there is a setting (amongst others) for it since db-mysql 0.5.7. Specifically set the option reconnect to true when creating the Database instance. Refer to the db-mysql connection documentation for this and other options.

Oh! Thank you for advice about the options. Had not noticed them before.

Your project is developing rapidly. Keep it up!

@zerodivisi0n zerodivisi0n reopened this May 29, 2011


mariano commented May 30, 2011

This has been fixed in db-mysql 0.6.2 by doing the following:

  1. The reconnect option is enabled by default
  2. The Database.isConnected() method properly pings the server to check status of connection

Check the release announcement and update to the latest db-mysql release

@mariano mariano closed this May 30, 2011

I think that pinging the server is not a best solution for checking connection. Is whether a way to emit event when the connection is dropping?


mariano commented May 31, 2011

The pinging only happens when you issue Database.isConnected(). Internally I'm not doing anything with pinging, it would make no sense to do so.

As far as I know there is no way in the MYSQL API to be informed of a dropped connection. That's why the 'reconnect' setting is there: to automatically reconnect in the event of a connection drop. If MySQL was able to tell you when it dropped, then reconnect would be moot.

As per the MySQL API, ping is the way to determine if a connection is alive. The only other alternative is to check the thread_id() of the connection against the previous thread_id(). If it's different, it means a reconnection occured. But that just serves no purpose other than irrelevant information, imho

I've got the following error when trying to use reconnect flag:

> var db_mysql = require('db-mysql')
> var db = new db_mysql.Database({reconnect: true})
node: symbol lookup error: /home/zerodivisi0n/node/lib/node_modules/db-mysql/build/default/mysql_bindings.node: undefined symbol: _ZN13node_db_mysql10Connection12setReconnectEb

mariano commented Jun 6, 2011

Fixed in ef347f2

Update to latest db-mysql. View 0.6.4 release announcement

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