diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 5825e63c097..368a7b39217 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -126,7 +126,6 @@ async function handleRequestDetail( lastPromise: Promise ): Promise { const { textsecure } = window; - const envelope: any = SignalService.Envelope.decode(plaintext); // After this point, decoding errors are not the server's @@ -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( diff --git a/ts/session/snode_api/serviceNodeAPI.ts b/ts/session/snode_api/serviceNodeAPI.ts index 7dad5fdee52..0d1bf96af2c 100644 --- a/ts/session/snode_api/serviceNodeAPI.ts +++ b/ts/session/snode_api/serviceNodeAPI.ts @@ -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 []; } } diff --git a/ts/session/snode_api/swarmPolling.ts b/ts/session/snode_api/swarmPolling.ts index b481bd4ed2b..ac2eaacc78c 100644 --- a/ts/session/snode_api/swarmPolling.ts +++ b/ts/session/snode_api/swarmPolling.ts @@ -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); @@ -48,8 +47,7 @@ export class SwarmPolling { public async start(): Promise { this.loadGroupIds(); - // tslint:disable: no-floating-promises - this.pollForAllKeys(); + void this.pollForAllKeys(); } public addGroupId(pubkey: PubKey) { @@ -133,7 +131,7 @@ export class SwarmPolling { const lastMessage = _.last(messages); - this.updateLastHash( + await this.updateLastHash( edkey, pubkey, lastMessage.hash, @@ -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(