Skip to content
Snippets Groups Projects
Commit 5fb7f030 authored by Gilles Filippini's avatar Gilles Filippini Committed by Benoit Lavenier
Browse files

fix(sync): don't lose nodes on single download err

`P2pCandidate.dlPromise` promise doesn't resolve on download errors
such as socket timeouts. Each time such an error occurs, the node is lost
for the sync because the 'this.dlPromise.isResolved()' check used for
testing the node's availability never succeeds anymore for this node.

This patch hardens the blocks downloading in two ways:
* Retrying the download up to 5 times when the number of returned blocks is
  different from what was requested
* On failure returns an empty block array so that the dlPromise is resolved
  and the node failure could be handled as expected at the P2PSyncDownloader
  level triggering the `P2pCandidate.addFailure()` function.
parent 8ef61d86
No related branches found
No related tags found
1 merge request!1427fix(sync): don't lose nodes on single download err
Pipeline #32250 failed
...@@ -90,21 +90,30 @@ export class P2pCandidate { ...@@ -90,21 +90,30 @@ export class P2pCandidate {
this.dlPromise = querablep( this.dlPromise = querablep(
(async () => { (async () => {
// We try to download the blocks // We try to download the blocks
let blocks: BlockDTO[] | null; let blocks: BlockDTO[] = [];
let tries = 5;
while (tries > 0) {
try { try {
blocks = await (this.api as IRemoteContacter).getBlocks(count, from); blocks = await (this.api as IRemoteContacter).getBlocks(
count,
from
);
} catch (e) { } catch (e) {
// Unfortunately this can fail // Unfortunately this can fail
blocks = null; blocks = [];
error = e; 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); this.responseTimes.push(Date.now() - start);
// Only keep a flow of 5 ttas for the node // Only keep a flow of 5 ttas for the node
if (this.responseTimes.length > 5) this.responseTimes.shift(); if (this.responseTimes.length > 5) this.responseTimes.shift();
this.nbSuccess++; this.nbSuccess++;
if (error) {
throw error;
}
return blocks; return blocks;
})() })()
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment