From 456b9568ff90a9c94feeed945011f7d7f68cc770 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 28 Apr 2019 09:58:15 -0700 Subject: [PATCH] 0.2.13 add better error handling to avoid reconnrest execpetion --- package.json | 2 +- src/socket-class.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6741546..0a60dcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uci/socket", - "version": "0.2.12", + "version": "0.2.13", "description": "JSON packet intra(named)/inter(TCP) host communication over socket", "main": "src", "scripts": { diff --git a/src/socket-class.js b/src/socket-class.js index be4f9d6..cfe5ec8 100644 --- a/src/socket-class.js +++ b/src/socket-class.js @@ -171,6 +171,20 @@ export default function socketClass(Server) { log.debug({method:'_listen', line:171, conPacket: this.opts.conPacket, msg:'pushing a preset command to just connected consumer'}) send(await stream.serialize(this.opts.conPacket)) // send a packet command on to consumer on connection } + + // add error and close listeners on connection + socket.on('error', (err) => { + log.error({msg:'client connection error during listen',error:err}) + }) + + socket.on('close', (msg) => { + log.warn({msg:'client connection closed during listen',error:msg}) + }) + + stream.on('error', (err) => { + log.error({msg:'client-socket stream error during listen',error:err}) + }) + socket.on('data', stream.onData) // TODO need to start error listener for stream so errors can be processed stream.on('message', messageProcess.bind(this, socket))