node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Allow to restore nodes after failed connections

Open juliomarmin opened this issue 2 years ago • 2 comments

In the mysql library which is used as inspiration for this library and has quite similar API, PoolCluster has the attribute restoreNodeTimeout: a node which failed the number of times removeNodeErrorCount can be recovered to the cluster after the time specified in restoreNodeTimeout.

mysql2 has a more radical behavior by which a node is removed from the cluster forever after the removeNodeErrorCount

In our use case, we have several remote nodes; anytime one of the nodes could become unavailable, and be later recovered. With the current mysql2 behavior it will not be included again in the cluster; eventually, all nodes could become unavailable at some points, meaning the cluster will be empty, even when some nodes are available.

Rather than trying to solve it on the application, by detecting that a node has been removed from the cluster and adding it again, it would be nice if mysql2 could recover those nodes after an specified time, in a similar way as mysql implements.

juliomarmin avatar Dec 09 '23 00:12 juliomarmin

PoolCluster is almost entirely reused/copied from mysqljs/mysql, if there are newer changes there I'm happy to see them backported. PRs welcome @juliomarmin :)

sidorares avatar Dec 09 '23 03:12 sidorares

For context

From mysqljs/mysql Documentation:

PoolCluster options

* `restoreNodeTimeout`: If connection fails, specifies the number of milliseconds

Server disconnects

With PoolCluster, disconnected connections will count as errors against the
related node, incrementing the error code for that node. Once there are more than
`removeNodeErrorCount` errors on a given node, it is removed from the cluster.
When this occurs, the PoolCluster may emit a `POOL_NONEONLINE` error if there are
no longer any matching nodes for the pattern. The `restoreNodeTimeout` config can
be set to restore offline nodes after a given timeout.

wellwelwel avatar Jan 11 '24 22:01 wellwelwel