Skip to content

Commit 309810c

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 309810c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

services/ndd_service.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,22 @@ class NddService {
9595
const pipeName = `node-ndb.${process.pid}.sock`;
9696
this._pipe = path.join(pipePrefix, pipeName);
9797
const server = net.createServer(socket => {
98+
let 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+
let data = Buffer.concat(chunks);
104+
const runSession = await this._startSession(JSON.parse(data), frontend);
100105
socket.write('run');
101106
runSession();
102-
});
107+
})
103108
socket.on('error', e => caughtErrorDebug(e));
104109
}).listen(this._pipe);
105110
server.unref();
106111
}
107112

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

0 commit comments

Comments
 (0)