diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-09-30 12:25:13 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-30 12:25:13 -0500 |
commit | 22e7a7947900cc974715b0c9d1d6b1a44d2ed1eb (patch) | |
tree | 918ab95c4f465c9c1fbfcd6706483e3310a38ce5 /streaming | |
parent | 63046c8cb9df8e797d53566f2050313d757b089b (diff) | |
parent | b5edf30160eab3776e44b34325a4ea00d9f71dc5 (diff) |
Merge remote-tracking branch 'upstream/master' into merge-glitch
Diffstat (limited to 'streaming')
-rw-r--r-- | streaming/index.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/streaming/index.js b/streaming/index.js index 62f6b5fe0..e4a5feb21 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -81,6 +81,19 @@ const redisUrlToClient = (defaultConfig, redisUrl) => { const numWorkers = +process.env.STREAMING_CLUSTER_NUM || (env === 'development' ? 1 : Math.max(os.cpus().length - 1, 1)); +/** + * @param {string} json + * @return {Object.<string, any>|null} + */ +const parseJSON = (json) => { + try { + return JSON.parse(json); + } catch (err) { + log.error(err); + return null; + } +}; + const startMaster = () => { if (!process.env.SOCKET && process.env.PORT && isNaN(+process.env.PORT)) { log.warn('UNIX domain socket is now supported by using SOCKET. Please migrate from PORT hack.'); @@ -524,7 +537,9 @@ const startWorker = (workerId) => { log.verbose(req.requestId, `Starting stream from ${ids.join(', ')} for ${accountId}${streamType}`); const listener = message => { - const { event, payload, queued_at } = JSON.parse(message); + const json = parseJSON(message); + if (!json) return; + const { event, payload, queued_at } = json; const transmit = () => { const now = new Date().getTime(); @@ -954,7 +969,9 @@ const startWorker = (workerId) => { ws.on('error', onEnd); ws.on('message', data => { - const { type, stream, ...params } = JSON.parse(data); + const json = parseJSON(data); + if (!json) return; + const { type, stream, ...params } = json; if (type === 'subscribe') { subscribeWebsocketToChannel(session, firstParam(stream), params); |