fix: fix retry logic
This commit is contained in:
parent
a021243c89
commit
1221d7de63
|
@ -461,7 +461,7 @@ export class P2PService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async connectToNode(connectionUris: URL[]): Promise<void> {
|
async connectToNode(connectionUris: URL[], retried = false): Promise<void> {
|
||||||
const unsupported = new URL("http://0.0.0.0");
|
const unsupported = new URL("http://0.0.0.0");
|
||||||
unsupported.protocol = "unsupported";
|
unsupported.protocol = "unsupported";
|
||||||
|
|
||||||
|
@ -493,8 +493,6 @@ export class P2PService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let retried = false;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.logger.verbose(`[connect] ${connectionUri}`);
|
this.logger.verbose(`[connect] ${connectionUri}`);
|
||||||
if (protocol === "tcp:") {
|
if (protocol === "tcp:") {
|
||||||
|
@ -513,26 +511,18 @@ export class P2PService {
|
||||||
await this.onNewPeer(peer, true);
|
await this.onNewPeer(peer, true);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (retried) return;
|
if (retried) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
retried = true;
|
retried = true;
|
||||||
|
|
||||||
this.logger.catched(e);
|
this.logger.catched(e);
|
||||||
|
|
||||||
/* if (e instanceof SocketException) {
|
const delay = this.reconnectDelay.get(id.toString())!;
|
||||||
if (e.message === "Connection refused") {
|
this.reconnectDelay.set(id.toString(), delay * 2);
|
||||||
this.logger.warn(`[!] ${id}: ${e}`);
|
|
||||||
} else {
|
|
||||||
this.logger.catched(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.logger.catched(e);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
const delay = this.reconnectDelay.get(id)!;
|
|
||||||
this.reconnectDelay.set(id, delay * 2);
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, delay * 1000));
|
await new Promise((resolve) => setTimeout(resolve, delay * 1000));
|
||||||
|
|
||||||
await this.connectToNode(connectionUris);
|
await this.connectToNode(connectionUris, retried);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue