Skip to content

Commit f839cf6

Browse files
committed
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 GoogleChromeLabs#319
1 parent ade2052 commit f839cf6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

services/ndd_service.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ class NddService {
9595
const pipeName = `node-ndb.${process.pid}.sock`;
9696
this._pipe = path.join(pipePrefix, pipeName);
9797
const server = net.createServer(socket => {
98+
const chunks = [];
9899
socket.on('data', async d => {
99-
const runSession = await this._startSession(JSON.parse(d), frontend);
100+
chunks.push(d);
101+
});
102+
socket.on('end', async() => {
103+
const data = Buffer.concat(chunks);
104+
const runSession = await this._startSession(JSON.parse(data), frontend);
100105
socket.write('run');
101106
runSession();
102107
});
@@ -105,6 +110,7 @@ class NddService {
105110
server.unref();
106111
}
107112

113+
108114
dispose() {
109115
process.disconnect();
110116
}

0 commit comments

Comments
 (0)