sidorares / sidorares/node-mysql2

error ER_CLIENT_INTERACTION_TIMEOUT 4031 fires randomly

Open
#1,925 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

Andrey wrote that using a pool automatically solves problems with loss of connection to the server and missing connection.

But simple code show that the error occurs randomly.

Error: The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.
code: 'ER_CLIENT_INTERACTION_TIMEOUT',
errno: 4031,

Code to reproduce:

import mysql from 'mysql2/promise';

const pool = mysql.createPool({
  port: parseInt(process.env.MYSQL_PORT),
  user: process.env.MYSQL_USER,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DBNAME,
  host: process.env.MYSQL_HOST,
  namedPlaceholders: true,
});
let counterG = 0;

for (let i = 0; i < 20; i++) {
  console.log('>>>> ', i);

  try {
   // any valid sql
    const [data] = await pool.query(`select * from user_profiles limit 1`);
    // @ts-ignore
    console.log('idUser : ', data[0].idUser, ' counterG ', counterG++);
  } catch (err) {
    console.log('*************** ERROR ', err.errno, counterG);
  }

  await delay(30_000);
}
process.exit(0);

In my case output was:

>>>>  0
idUser :  0  counterG  0
>>>>  1
idUser :  0  counterG  1
>>>>  2
idUser :  0  counterG  2
>>>>  3
idUser :  0  counterG  3
>>>>  4
idUser :  0  counterG  4
>>>>  5
Warning: got packets out of order. Expected 1 but received 0
*************** ERROR  4031 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied mysql2/promise pool reproduction and inspect connection reuse, server-disconnect handling, and the "packets out of order" path. Done means the 30-second query loop no longer fails with ER_CLIENT_INTERACTION_TIMEOUT 4031 and the reproduced behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js, typescript
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.