diff --git a/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts b/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts index 8f81ed886764eee8f5bd31571fc27921ccfc7f5a..6b6403bbcc4638d894ee365ccd3b5709015ac64e 100644 --- a/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts +++ b/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts @@ -90,21 +90,30 @@ export class P2pCandidate { this.dlPromise = querablep( (async () => { // We try to download the blocks - let blocks: BlockDTO[] | null; - try { - blocks = await (this.api as IRemoteContacter).getBlocks(count, from); - } catch (e) { - // Unfortunately this can fail - blocks = null; - error = e; + let blocks: BlockDTO[] = []; + let tries = 5; + while (tries > 0) { + try { + blocks = await (this.api as IRemoteContacter).getBlocks( + count, + from + ); + } catch (e) { + // Unfortunately this can fail + blocks = []; + this.logger.error(e); + } + if (blocks.length != count) { + this.logger.error("Wrong number of blocks from %s", this.hostName); + tries--; + } else { + break; + } } this.responseTimes.push(Date.now() - start); // Only keep a flow of 5 ttas for the node if (this.responseTimes.length > 5) this.responseTimes.shift(); this.nbSuccess++; - if (error) { - throw error; - } return blocks; })() );