From 8b1660220363c447563662a91c6f8e0507063fc8 Mon Sep 17 00:00:00 2001 From: Ray Marceau Date: Sat, 10 Oct 2020 12:46:23 -0700 Subject: [PATCH] fix(NddService): fix NddService socket.on('data') for large input This patch fixes NddService.server socker.on('data') so that it can handle large amounts of input without throwing `SyntaxError: Unexpected end of JSON input` errors. Fixes #319 --- services/ndd_service.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/ndd_service.js b/services/ndd_service.js index 5dd54d95..bf25112a 100644 --- a/services/ndd_service.js +++ b/services/ndd_service.js @@ -95,8 +95,13 @@ class NddService { const pipeName = `node-ndb.${process.pid}.sock`; this._pipe = path.join(pipePrefix, pipeName); const server = net.createServer(socket => { + const chunks = []; socket.on('data', async d => { - const runSession = await this._startSession(JSON.parse(d), frontend); + chunks.push(d); + }); + socket.on('end', async() => { + const data = Buffer.concat(chunks); + const runSession = await this._startSession(JSON.parse(data), frontend); socket.write('run'); runSession(); });