Skip to content

Commit

Permalink
fix polling logic on network errors #995
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Sep 7, 2020
1 parent b5f31a4 commit 7501d71
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ts/receiver/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async function handleRequestDetail(
lastPromise: Promise<any>
): Promise<void> {
const { textsecure } = window;

const envelope: any = SignalService.Envelope.decode(plaintext);

// After this point, decoding errors are not the server's
Expand Down Expand Up @@ -166,7 +165,9 @@ async function handleRequestDetail(
// receiving pipeline refactor. It is to be implemented in the next PR.

// To ensure that we queue in the same order we receive messages

await lastPromise;

queueEnvelope(envelope);
} catch (error) {
window.log.error(
Expand Down
2 changes: 2 additions & 0 deletions ts/session/snode_api/serviceNodeAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ export async function retrieveNextMessages(
const json = JSON.parse(res.body);
return json.messages || [];
} catch (e) {
window.log.warn('exception while parsing json of nextMessage:', e);

return [];
}
}
Expand Down
17 changes: 9 additions & 8 deletions ts/session/snode_api/swarmPolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function processMessage(message: string, options: any = {}) {
try {
const dataPlaintext = new Uint8Array(StringUtils.encode(message, 'base64'));
const messageBuf = SignalService.WebSocketMessage.decode(dataPlaintext);

if (messageBuf.type === SignalService.WebSocketMessage.Type.REQUEST) {
// tslint:disable-next-line no-floating-promises
Receiver.handleRequest(messageBuf.request?.body, options);
Expand All @@ -48,8 +47,7 @@ export class SwarmPolling {

public async start(): Promise<void> {
this.loadGroupIds();
// tslint:disable: no-floating-promises
this.pollForAllKeys();
void this.pollForAllKeys();
}

public addGroupId(pubkey: PubKey) {
Expand Down Expand Up @@ -133,7 +131,7 @@ export class SwarmPolling {

const lastMessage = _.last(messages);

this.updateLastHash(
await this.updateLastHash(
edkey,
pubkey,
lastMessage.hash,
Expand Down Expand Up @@ -187,10 +185,13 @@ export class SwarmPolling {
const groupPromises = this.groupPubkeys.map(async pk => {
return this.pollOnceForKey(pk, true);
});

await Promise.all(_.concat(directPromises, groupPromises));

setTimeout(this.pollForAllKeys.bind(this), 2000);
try {
await Promise.all(_.concat(directPromises, groupPromises));
} catch (e) {
window.log.warn('pollForAllKeys swallowing exception: ', e);
} finally {
setTimeout(this.pollForAllKeys.bind(this), 2000);
}
}

private async updateLastHash(
Expand Down

0 comments on commit 7501d71

Please sign in to comment.