Skip to content

Commit

Permalink
fix(NddService): fix NddService socket.on('data') for large input
Browse files Browse the repository at this point in the history
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 GoogleChromeLabs#319
  • Loading branch information
razorman8669 committed Oct 10, 2020
1 parent ade2052 commit 8b16602
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion services/ndd_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 8b16602

Please sign in to comment.