Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda