Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR After 8 PM

I have a problem about connecting to MySQL. After 8 PM (My local time), the connection is lost. So I modified my code, whenever mysql throw PROTOCOL_CONNECTION_LOST, it will try to reconnect to the mysql. The error for PROTOCOL_CONNECTION_LOST is gone, but it give new error code PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR when trying to connect to the server. This is my code to create connection to MySQL.

const dbConn = mysql.createConnection({
    host        : 'localhost',
    user        : 'xxxx',
    password    : 'xxxx',
    database    : 'test'
});

function handleDisconnect() {

  dbConn.connect(function(err, connection) {             
    if(err) {                                     
      console.log('error when connecting to db:', err);
      setTimeout(handleDisconnect, 2000); 
    }       
  });                                     
   
  dbConn.on('error', function(err) {
    console.log('db error', err);
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { 
      handleDisconnect();                         
    } else {                                     
      throw(err)                       
    }
  });
}

handleDisconnect();
module.exports = dbConn;

This is my error stack

0|index    | error when connecting to db: Error: Cannot enqueue Handshake after fatal error.
0|index    |     at Protocol._validateEnqueue (/home/mydev/SOBATku/node_modules/mysql/lib/protocol/Protocol.js:212:16)
0|index    |     at Protocol._enqueue (/home/mydev/SOBATku/node_modules/mysql/lib/protocol/Protocol.js:138:13)
0|index    |     at Protocol.handshake (/home/mydev/SOBATku/node_modules/mysql/lib/protocol/Protocol.js:51:23)
0|index    |     at Connection.connect (/home/mydev/SOBATku/node_modules/mysql/lib/Connection.js:116:18)
0|index    |     at handleDisconnect (/home/mydev/SOBATku/config/db.config.js:34:10)
0|index    |     at Connection.<anonymous> (/home/mydev/SOBATku/config/db.config.js:45:7)
0|index    |     at Connection.emit (node:events:390:28)
0|index    |     at Connection._handleProtocolError (/home/mydev/SOBATku/node_modules/mysql/lib/Connection.js:423:8)
0|index    |     at Protocol.emit (node:events:390:28)
0|index    |     at Protocol._delegateError (/home/mydev/SOBATku/node_modules/mysql/lib/protocol/Protocol.js:398:10) {
0|index    |   code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',
0|index    |   fatal: false
0|index    | }

It can reconnect when I do some command like pm2 logs or other command with pm2 (I use pm2 for node run command). Planning to use cron function to restart my service every 8PM, but if it can solved without restart the service, it will be very helpful. Thank you.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!