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

136
Views
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
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!