From 2eddb65c965853842c3ee217be8f62d28796f803 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 10 Oct 2020 20:23:16 +0200 Subject: [PATCH] Fix missing error if initial connection cannot be established. E.g. if the IP address of the server is wrong: Currently the socket setup just runs forever, but the situation of a wrong server address should better be handled somehow. --- dcom/rpc/stub.js | 2 +- dcom/transport/comtransport.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dcom/rpc/stub.js b/dcom/rpc/stub.js index 8a439334..29a064d4 100755 --- a/dcom/rpc/stub.js +++ b/dcom/rpc/stub.js @@ -87,7 +87,7 @@ class Stub extends Events.EventEmitter { transport = this.endpoint.transport; await transport.attach() .catch(function(reject) { - debug(reject); + throw new Error(reject) }); } diff --git a/dcom/transport/comtransport.js b/dcom/transport/comtransport.js index b4616f8c..9b24ae1a 100755 --- a/dcom/transport/comtransport.js +++ b/dcom/transport/comtransport.js @@ -108,6 +108,7 @@ class ComTransport extends events.EventEmitter channel.on('error', function(data){ self.emit('disconnected'); + reject(data) }); channel.on('close', function(){ @@ -116,7 +117,10 @@ class ComTransport extends events.EventEmitter } }); + const connectFailedTimer = setTimeout(() => + channel.emit('error', 'Connection could not be established'), self.timeout) channel.connect(Number.parseInt(self.port), self.host, () => { + clearTimeout(connectFailedTimer) self.attached = true; channel.setKeepAlive(true); self.channelWrapper = channel;