Registry / database / node-mysql-deadlock-retries

node-mysql-deadlock-retries

JSON →
library2.0.5jsnpmunverified

Provides retry capabilities for node-mysql queries that fail with MySQL deadlock errors (errno 1205-1213, ER_LOCK_DEADLOCK, ERR_LOCK_WAIT_TIMEOUT). It proxies the connection's query method, retrying failed queries up to a configurable number of times with random sleep intervals between retries. Version 2.0.5, stable, low release cadence (last update 2017). Differentiator: simple, focused deadlock handling for the node-mysql driver, vs. generic retry libraries.

npm install node-mysql-deadlock-retries
INSTALL
IMPORT
SIG · NODE-MYSQL-DEADLOC
N
node-mysql-deadlock-retries
databasejavascriptv2.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const proxyDeadlock = require('node-mysql-deadlock-retries');
import proxyDeadlock from 'node-mysql-deadlock-retries';
CommonJS only; no ESM export available.
proxyMysqlDeadlockRetries
const proxyMysqlDeadlockRetries = require('node-mysql-deadlock-retries');
The exported function is assigned to module.exports directly, so the default import is the function itself.
no symbol (function call)
proxyMysqlDeadlockRetries(connection, retries, minMillis, maxMillis, debug, show_all_errors);
The function modifies the MySQL connection in-place by overriding its query method.

Installs and uses node-mysql-deadlock-retries to add deadlock retry logic to a MySQL connection, then runs a simple query.

const mysql = require('mysql'); const proxyDeadlock = require('node-mysql-deadlock-retries'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test' }); connection.connect(); proxyDeadlock(connection, 5, 1, 100, 0, 0); connection.query('SELECT * FROM users', function(err, rows) { if (err) throw err; console.log(rows); }); connection.end();
Debug
Known issues
gotchaThe library requires the node-mysql package as a peer dependency but does not declare it in package.json. Ensure mysql is installed.
fix
npm install mysql
affects: *
gotchaRelease 2.0.0 changed retry logic; ensure you read the changelog if upgrading from 1.x.
fix
Review the behavior change in retry handling.
affects: >=2.0.0 <3.0.0
deprecatedThe readme references 'var retries: 5' which mixes JavaScript and TypeScript syntax; treat as plain JS.
fix
Use 'var retries = 5;' in JavaScript.
affects: *
gotchaWhen using connection pools, the proxy must be applied on each new connection via the 'connection' event.
fix
dbPool.on('connection', function(connection) { proxyDeadlock(connection, ...); });
affects: *
gotchaThe library does not handle MySQL2/mysql2 package; only works with the 'mysql' package.
fix
Use 'mysql' instead of 'mysql2'.
affects: *
Errors
Common errors & fixes
Cannot find module 'node-mysql-deadlock-retries'
Package not installed.
fix
npm install node-mysql-deadlock-retries --save
Cannot read property 'query' of undefined
Proxy applied before connection object is fully created.
fix
Call proxyDeadlock(connection, ...) after connection is created but before first use.
TypeError: proxyMysqlDeadlockRetries is not a function
Using ES6 import style incorrectly.
fix
Use const proxyMysqlDeadlockRetries = require('node-mysql-deadlock-retries');
ER_LOCK_DEADLOCK: Deadlock found when trying to get lock; try restarting transaction
Query failed due to deadlock but retries exhausted or not configured.
fix
Increase retries/minMillis/maxMillis or optimize queries.
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
node-mysql-deadlock-retries — npm install node-mysql-deadlock-retries · libregistry