From 4e481b37b8f29e09ef4d6a8596cc51b517808358 Mon Sep 17 00:00:00 2001 From: Moe Alam Date: Wed, 30 Sep 2020 21:50:07 -0700 Subject: [PATCH] fix p2p memory leak with streaming http methods --- libs/commander/worker.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/commander/worker.js b/libs/commander/worker.js index 24f46b2e..b68474f7 100644 --- a/libs/commander/worker.js +++ b/libs/commander/worker.js @@ -57,16 +57,16 @@ const initialize = (config,lang) => { if(method === 'GET' && data){ requestEndpoint += '?' + createQueryStringFromObject(data) } - return request(requestEndpoint,{ + const theRequest = request(requestEndpoint,{ method: method, json: method !== 'GET' ? (data ? data : null) : null - }, function(err,resp,body){ + }, typeof callback === 'function' ? (err,resp,body) => { // var json = parseJSON(body) if(err)console.error(err,data) callback(err,body,resp) - }).on('data', function(data) { - onDataReceived(data) - }) + } : null) + .on('data', onDataReceived); + return theRequest } const createShinobiSocketConnection = (connectionId) => { const masterConnectionToMachine = socketIOClient(`ws://localhost:${config.port}`, {transports:['websocket']}) @@ -103,13 +103,13 @@ const initialize = (config,lang) => { rawRequest.url, rawRequest.method, rawRequest.data, - function(err,json,resp){ + rawRequest.focus !== 'mp4' && rawRequest.focus !== 'flv' && rawRequest.focus !== 'mjpeg' && rawRequest.focus !== 'h264' ? function(err,json,resp){ connectionToP2PServer.emit('httpResponse',{ err: err, json: rawRequest.bodyOnEnd ? json : null, rid: rawRequest.rid }) - }, + } : null, (data) => { if(!rawRequest.bodyOnEnd)connectionToP2PServer.emit('httpResponseChunk',{ data: data,