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

135
Vistas
socketio/nodejs chat crash json file

We built a chat in nodejs/socketIO and it works well. We use pm2 to start it. Today we faced an issue and chat crashed :-(

All messages are saved in json file (so in json format) in using :

// reading 
if (fs.existsSync(dataPathFile)) {
      this.messages = JSON.parse(fs.readFileSync(dataPathFile, "UTF-8"));
    } else {
      this.messages = [];
    }
}
...
// recording
fs.writeFile(dataPathFile, JSON.stringify(this.messages), "UTF-8", function (err) {
      if (err) throw err;
    });
return message;
...

logs give us :

SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at new Message (/appli/chatvideodiff/server/utils/message.js:11:28)

=> line 11 is reading line "this.messages"

We have no idea what could be wrong but when issue appears :

  • memory usage increases until max (1)
  • json file becomes empty
  • cpu does yoyo (often 100% usage (htop))

(1) : in logs we have

PM2     | [PM2][WORKER] Process 0 restarted because it exceeds --max-memory-restart value (current_memory=2001776640 max_memory_limit=1073741824 [octets])

We increased "max_memory_limit" to "14000" (14 GB as we have 16 GB) but it crashes also

We planned to switch from json file to database but if you have an idea to fix issue faster, we are for sure interested.

Thanks for your help Niko

if that can help, messages are like that :

{
    "from": "Niko",
    "text": "test niko",
    "room": "03a74",
    "ip": "1.1.1.1",
    "color": "#5073C7",
    "id": "ea1c86d8-6f8e-ddce-d525-925e4a6da861",
    "createdAt": 1637769784314
}
about 4 years ago · Juan Pablo Isaza
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