diff --git a/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts b/app/modules/crawler/lib/sync/p2p/p2p-candidate.ts index 56fca9b04b8781f9f514e5856ba6aae67eb05351..65366d71e2230803e8302085fb1e951b8c8fc90a 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; })() );