2

I'm running a node.js server but I'm also running - but too bad straight into a really big bug:

Exactly every eight hours the server closes connection, crashes and produces this error message:

{ Error: Connection lost: The server closed the connection.
    at Protocol.end (/home/node/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
    at Socket.<anonymous> (/home/node/app/node_modules/mysql/lib/Connection.js:97:28)
    at Socket.<anonymous> (/home/node/app/node_modules/mysql/lib/Connection.js:502:10)
    at Socket.emit (events.js:187:15)
    at endReadableNT (_stream_readable.js:1092:12)
    at process._tickCallback (internal/process/next_tick.js:63:19) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }

I'm aware that this error comes from mysql so I spent a few hours googling for solutions. But for me none of them seems to work.

  • Catching the error PROTOCOL_CONNECTION_LOST

con.on('error', function(err) {
    mysqlConnection();
})

con.on('close', function(err) {
    mysqlConnection();
})

function mysqlConnection() {
  con = mysql.createConnection({
      host: "xy",
      user: "xy",
      password: "xy",
      database: "xy",
  });
  con.connect(function(error) {})
}
  • Sending queries in timeout (3,600,000)

setInterval(function () {
    con.query("SELECT * FROM xy", [], (err,result,fields)=>{})
}, 3600000); // every hour
  • simulating the connection drop

con.destroy();

It seems that no-one of the fixes is working for me. So I hope I can get an update to some already outdated questions & answers I found.

Harshith Rai
  • 3,018
  • 7
  • 22
  • 35
  • any details other then this so far ? i am having the same problem, guess only option is to increase wait timeout from mysql. – Adeel Ahmed Aug 09 '19 at 20:11

0 Answers0