Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: timeout error crashing explorer #253

Merged
merged 1 commit into from
Jun 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions app/platform/fabric/gateway/FabricGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,26 @@ export class FabricGateway {
if (!this.waitingResp) {
this.waitingResp = true;
logger.info('Sending discovery request...');
await this.ds.send({
asLocalhost: this.asLocalhost,
requestTimeout: 5000,
refreshAge: 15000,
targets: this.dsTargets
});
logger.info('Succeeded to send discovery request');
await this.ds
.send({
asLocalhost: this.asLocalhost,
requestTimeout: 5000,
refreshAge: 15000,
targets: this.dsTargets,
})
.then(() => {
logger.info('Succeeded to send discovery request');
})
.catch(error => {
if (error) {
logger.warn(
'Failed to send discovery request for channel',
error,
);
this.waitingResp = false;
this.ds.close();
}
});
} else {
logger.info('Have already been sending a request');
return null;
Expand Down
11 changes: 9 additions & 2 deletions app/platform/fabric/sync/SyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ export class SyncServices {
async syncBlocks(client, channel_name) {
const network_id = client.getNetworkId();

// Get channel information from ledger
const channelInfo = await client.fabricGateway.queryChainInfo(channel_name);

if (!channelInfo) {
logger.info(
`syncBlocks: Failed to retrieve channelInfo >> ${channel_name}`,
);
return;
}
const synch_key = `${network_id}_${channel_name}`;
logger.info(`syncBlocks: Start >> ${synch_key}`);
if (this.synchInProcess.includes(synch_key)) {
Expand All @@ -368,8 +377,6 @@ export class SyncServices {
}
this.synchInProcess.push(synch_key);

// Get channel information from ledger
const channelInfo = await client.fabricGateway.queryChainInfo(channel_name);
const channel_genesis_hash = client.getChannelGenHash(channel_name);
const blockHeight = parseInt(channelInfo.height.low) - 1;
// Query missing blocks from DB
Expand Down
5 changes: 4 additions & 1 deletion app/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ process.on('unhandledRejection', (up : {message : string}) => {
} else {
logger.error(up);
}
shutDown();
// prevent timeout error from calling shutdown
if (!up.message.includes('REQUEST TIMEOUT')) {
shutDown();
}
});
process.on('uncaughtException', up => {
logger.error(
Expand Down
25 changes: 17 additions & 8 deletions app/test/FabricGateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sinon from 'sinon';
import { FabricGateway } from '../platform/fabric/gateway/FabricGateway';

// DiscoveryService (this.ds)
const stubSend = sinon.stub();
const stubSign = sinon.stub();
const stubGetDiscoveryResults = sinon.stub();
const stubClose = sinon.stub();
Expand All @@ -35,7 +36,7 @@ function getFabricGatewayInstance() {
return {
build: sinon.stub(),
sign: stubSign,
send: sinon.stub(),
send: stubSend,
getDiscoveryResults: stubGetDiscoveryResults,
close: stubClose
};
Expand Down Expand Up @@ -91,6 +92,7 @@ function getFabricGatewayInstance() {

function resetAllStubs() {
// DiscoveryService (this.ds)
stubSend.reset();
stubSign.reset();
stubGetDiscoveryResults.reset();
stubClose.reset();
Expand Down Expand Up @@ -173,18 +175,25 @@ describe('sendDiscoveryRequest', () => {
resetAllStubs();
});

it('should throw error when discoveryService.sends() throw error', async () => {
stubSend.rejects(Promise.reject(new Error('REQUEST TIMEOUT')));
await gw.sendDiscoveryRequest();
expect(stubWarn.called).be.equal(true);
expect(stubClose.calledOnce).be.equal(true);
});

it('should throw error when failed to call getDiscoveryResults()', async () => {
stubGetDiscoveryResults.throws();
await gw.sendDiscoveryRequest();
expect(stubWarn.called).be.equal(true);
expect(stubClose.calledOnce).be.equal(true);
});

it('should return without error', async () => {
stubGetDiscoveryResults.returns(Promise.resolve());
await gw.sendDiscoveryRequest();
expect(stubError.called).be.equal(false);
});

it('should throw error when failed to call getDiscoveryResults()', async () => {
stubGetDiscoveryResults.throws();
await gw.sendDiscoveryRequest();
expect(stubWarn.called).be.equal(true);
expect(stubClose.calledOnce).be.equal(true);
});
});

describe('getDiscoveryResult', () => {
Expand Down