Retry initialiseRandomPool some times if request fails, fix uncaught promise in sendMessage

pull/325/head
Beaudan 6 years ago
parent 87c5d0858c
commit 10e61c37da

@ -119,8 +119,15 @@ class LokiMessageAPI {
data: data64,
};
const promises = [];
let completedConnections = 0;
for (let i = 0; i < numConnections; i += 1) {
promises.push(this.openSendConnection(params));
const connectionPromise = this.openSendConnection(params).finally(() => {
completedConnections += 1;
if (completedConnections >= numConnections) {
delete this.sendingSwarmNodes[timestamp];
}
});
promises.push(connectionPromise);
}
// Taken from https://stackoverflow.com/questions/51160260/clean-way-to-wait-for-first-true-returned-by-promise
@ -142,7 +149,6 @@ class LokiMessageAPI {
let success;
try {
// eslint-disable-next-line more/no-then
Promise.all(promises).then(delete this.sendingSwarmNodes[timestamp]);
success = await firstTrue(promises);
} catch (e) {
if (e instanceof textsecure.WrongDifficultyError) {

@ -86,7 +86,7 @@ class LokiSnodeAPI {
];
}
async initialiseRandomPool() {
async initialiseRandomPool(attempts = 0) {
const params = {
limit: 20,
fields: {
@ -113,7 +113,10 @@ class LokiSnodeAPI {
port: snode.storage_port,
}));
} catch (e) {
throw new window.textsecure.SeedNodeError('Failed to contact seed node');
if (attempts >= window.seedNodeList.length) {
throw new window.textsecure.SeedNodeError('Failed to contact seed node');
}
this.initialiseRandomPool(attempts + 1);
}
}

Loading…
Cancel
Save