From b856710a3ba86beb198aa95cd89b70ff6e765cbb Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 12 Jul 2020 18:28:19 -0700 Subject: [PATCH] 0.3.2 catch no consumer on send --- package.json | 10 +++++----- src/socket-class.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b01b016..4cb068d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/socket", - "version": "0.3.1", + "version": "0.3.2", "description": "JSON packet intra(named)/inter(TCP) host communication over socket", "main": "src", "scripts": { @@ -43,16 +43,16 @@ "chai": "^4.2.0", "chai-as-promised": "^7.1.1", "esm": "^3.2.25", - "mocha": "^7.1.1", - "nodemon": "^2.0.2" + "mocha": "^8.0.1", + "nodemon": "^2.0.4" }, "dependencies": { - "@uci-utils/logger": "^0.0.16", + "@uci-utils/logger": "^0.0.18", "better-try-catch": "^0.6.2", "clone": "^2.1.2", "death": "^1.1.0", "delay": "^4.3.0", - "make-dir": "^3.0.2", + "make-dir": "^3.1.0", "p-reflect": "^2.1.0" } } diff --git a/src/socket-class.js b/src/socket-class.js index 2880589..aa6a858 100644 --- a/src/socket-class.js +++ b/src/socket-class.js @@ -477,12 +477,23 @@ export default function socketClass(Server) { async _send(consumer, packet) { log.trace({msg:`sending to consumer:${consumer.sid}:${consumer.data.name}`, consumer:consumer.data, packet:packet}) return new Promise(async (resolve, reject) => { + if (!consumer) { + console.log('no consumer rejecting packet send') + reject('no consumer specified can not send packet') + return + } if (!consumer.writable) { + console.log('no consumer writeable stream rejecting packet send') reject('socket stream closed can not send packet') return } let [err,ser] = await btc(consumer.stream.serialize)(packet) if (err) reject('unable to serialze the packet') + if (!ser) { + console.log('empty-seriallized packet', consumer.name, consumer.socketName) + reject('empty packet rejecting send, nothing to send') + return + } const cb = () => resolve('packet written to socket stream') if (!consumer.write(ser)) { consumer.once('drain', cb)