From fda3a3cfed93f2cf49220ee2f4e54fc7b01aa57d Mon Sep 17 00:00:00 2001 From: Rian Hunter Date: Mon, 20 Nov 2017 11:23:14 -0800 Subject: [PATCH] Returning error on pending callbacks when connection dies --- lib/bus.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/bus.js b/lib/bus.js index ea1e1975..941ad963 100644 --- a/lib/bus.js +++ b/lib/bus.js @@ -86,6 +86,16 @@ module.exports = function bus(conn, opts) { this.connection.message(reply); }; + this.connection.on('end', function() { + // complete all pending callbacks with error + var handler; + for (var cookie in self.cookies) { + handler = self.cookies[cookie]; + delete self.cookies[cookie]; + handler(new Error("connection was closed")); + } + }); + // route reply/error this.connection.on('message', function(msg) { var handler;