From a4c0fd257ada8af981c81e289a3fa0fa4fa0d1af Mon Sep 17 00:00:00 2001 From: Bret Harrison Date: Fri, 14 Dec 2018 18:35:19 -0500 Subject: [PATCH] FABN-1058 NodeSDK handler close peer Have the handler close the peer connection on error. Change-Id: Ic43a2e16ad3e4ad792fb61b954fa121c39a445b4 Signed-off-by: Bret Harrison --- fabric-client/lib/Channel.js | 7 +++++++ fabric-client/lib/Remote.js | 1 + fabric-client/lib/impl/DiscoveryEndorsementHandler.js | 1 + test/unit/remote.js | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/fabric-client/lib/Channel.js b/fabric-client/lib/Channel.js index 64c20fd5b8..add7b39c82 100755 --- a/fabric-client/lib/Channel.js +++ b/fabric-client/lib/Channel.js @@ -1258,6 +1258,13 @@ const Channel = class { return results; } } else { + if (response instanceof Error) { + if (response.connectFailed) { + logger.error(' Unable to get discovery results from peer %s', target_peer.getUrl()); + // close this peer down so that next time a new connection will be used + target_peer.close(); + } + } throw new Error('Discovery has failed to return results'); } } diff --git a/fabric-client/lib/Remote.js b/fabric-client/lib/Remote.js index f554a1de86..1e669bfbaf 100644 --- a/fabric-client/lib/Remote.js +++ b/fabric-client/lib/Remote.js @@ -153,6 +153,7 @@ class Remote { if (err.message) { err.message = err.message + ' URL:' + self.getUrl(); } + err.connectFailed = true; logger.error(err); return reject(err); diff --git a/fabric-client/lib/impl/DiscoveryEndorsementHandler.js b/fabric-client/lib/impl/DiscoveryEndorsementHandler.js index de4310c4ed..21ae2ec873 100644 --- a/fabric-client/lib/impl/DiscoveryEndorsementHandler.js +++ b/fabric-client/lib/impl/DiscoveryEndorsementHandler.js @@ -279,6 +279,7 @@ class DiscoveryEndorsementHandler extends api.EndorsementHandler { error = new Error(caught_error.toString()); // if this peer failed to connect then close it if (error.connectFailed) { + logger.warn('%s - connect fail to peer - %s', peer.getUrl()); peer.close(); } } else { diff --git a/test/unit/remote.js b/test/unit/remote.js index 94333b1c6a..77f4b92e6a 100644 --- a/test/unit/remote.js +++ b/test/unit/remote.js @@ -156,6 +156,11 @@ test('\n\n ** Remote node tests **\n\n', async (t) => { } catch (error) { if (error.toString().includes(peer.getUrl())) { t.pass('Successfully got the waitForReady URL address error'); + if (error.connectFailed) { + t.pass('Successfully got the connection failed set in the error'); + } else { + t.fail('Failed to get the connection failed set in the error'); + } } else { t.fail('Failed to get the waitForReady URL address error'); }