From ff0d9ac21e83def83b70575f8ee82b3907edfc0c 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/services/ndd_service.js b/services/ndd_service.js index 5dd54d95..63b61dbc 100644 --- a/services/ndd_service.js +++ b/services/ndd_service.js @@ -95,16 +95,22 @@ class NddService { const pipeName = `node-ndb.${process.pid}.sock`; this._pipe = path.join(pipePrefix, pipeName); const server = net.createServer(socket => { + let chunks = []; socket.on('data', async d => { - const runSession = await this._startSession(JSON.parse(d), frontend); + chunks.push(d) + }); + socket.on('end', async () => { + let data = Buffer.concat(chunks); + const runSession = await this._startSession(JSON.parse(data), frontend); socket.write('run'); runSession(); - }); + }) socket.on('error', e => caughtErrorDebug(e)); }).listen(this._pipe); server.unref(); } + dispose() { process.disconnect(); }