Skip to content

Commit

Permalink
FABN-1058 NodeSDK handler close peer
Browse files Browse the repository at this point in the history
Have the handler close the peer connection
on error.

Change-Id: Ic43a2e16ad3e4ad792fb61b954fa121c39a445b4
Signed-off-by: Bret Harrison <[email protected]>
  • Loading branch information
harrisob committed Dec 14, 2018
1 parent 89e8c4b commit a4c0fd2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
1 change: 1 addition & 0 deletions fabric-client/lib/Remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions fabric-client/lib/impl/DiscoveryEndorsementHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down

0 comments on commit a4c0fd2

Please sign in to comment.