Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
Node.js mysql read ECONNRESET

After searching for long time regarding this error and not really be able to figure out how to handle this error in my project. I need some help from you :).

I've got the problem, that my Screen with my Node-APP will give me a error after some hours (I don't know after how many hours but my feeling says me it isn't always the same time)

I will give you my error below. Does anyone know how to fix this? I already tried with an interval of select everything from one short table, to reset the connection to database, so the connection will not be closed, because there will be always (every 30 Minutes) a short call to the Database.

Also after I get the error and restart the app everything works fine. I saw its a idle-time problem, but I did not find any way to solve this problem for me. This is how I create the connection to my database.

var con = mysql.createConnection({
   host: process.env.DATABASE_HOST,
   user: process.env.DATABASE_USER,
   password: process.env.DATABASE_PASSWORD,
   database: process.env.DATABASE });


  con.connect(function(err) {
   if (err) throw err;
   console.log("Connected to Database!");
 });

Thank you very much in advance!

The best regards

The error:

node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET

    at TCP.onStreamRead (node:internal/stream_base_commons:211:20)
Emitted 'error' event on Connection instance at:
    at Connection._handleProtocolError (/var/www/xxx/xxx/node_modules/mysql/lib/Connection.js:423:8)
    at Protocol.emit (node:events:394:28)
    at Protocol._delegateError (/var/www/xxx/xxx/node_modules/mysql/lib/protocol/Protocol.js:398:10)
    at Protocol.handleNetworkError (/var/www/xxx/xxx/node_modules/mysql/lib/protocol/Protocol.js:371:10)
    at Connection._handleNetworkError (/var/www/xxx/xxx/node_modules/mysql/lib/Connection.js:418:18)
    at Socket.emit (node:events:394:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read',
  fatal: true
}

And again THANK YOU!!! :)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think it becuse of multipale DB connections

Use createPool instaed of createConnection and defile connectionLimit, acquireTimeout milliseconds so connection auto close after this time

var mysql = require('mysql');
var pool  = mysql.createPool({
  connectionLimit : 10,
  acquireTimeout  : 10000
  host            : 'example.org',
  user            : 'bob',
  password        : 'secret',
  database        : 'my_db'
});

pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda