fix polling logic on network errors #995

pull/1329/head
Audric Ackermann 5 years ago
parent b5f31a4f3f
commit 7501d71542
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -126,7 +126,6 @@ async function handleRequestDetail(
lastPromise: Promise<any> lastPromise: Promise<any>
): Promise<void> { ): Promise<void> {
const { textsecure } = window; const { textsecure } = window;
const envelope: any = SignalService.Envelope.decode(plaintext); const envelope: any = SignalService.Envelope.decode(plaintext);
// After this point, decoding errors are not the server's // 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. // receiving pipeline refactor. It is to be implemented in the next PR.
// To ensure that we queue in the same order we receive messages // To ensure that we queue in the same order we receive messages
await lastPromise; await lastPromise;
queueEnvelope(envelope); queueEnvelope(envelope);
} catch (error) { } catch (error) {
window.log.error( window.log.error(

@ -387,6 +387,8 @@ export async function retrieveNextMessages(
const json = JSON.parse(res.body); const json = JSON.parse(res.body);
return json.messages || []; return json.messages || [];
} catch (e) { } catch (e) {
window.log.warn('exception while parsing json of nextMessage:', e);
return []; return [];
} }
} }

@ -21,7 +21,6 @@ export function processMessage(message: string, options: any = {}) {
try { try {
const dataPlaintext = new Uint8Array(StringUtils.encode(message, 'base64')); const dataPlaintext = new Uint8Array(StringUtils.encode(message, 'base64'));
const messageBuf = SignalService.WebSocketMessage.decode(dataPlaintext); const messageBuf = SignalService.WebSocketMessage.decode(dataPlaintext);
if (messageBuf.type === SignalService.WebSocketMessage.Type.REQUEST) { if (messageBuf.type === SignalService.WebSocketMessage.Type.REQUEST) {
// tslint:disable-next-line no-floating-promises // tslint:disable-next-line no-floating-promises
Receiver.handleRequest(messageBuf.request?.body, options); Receiver.handleRequest(messageBuf.request?.body, options);
@ -48,8 +47,7 @@ export class SwarmPolling {
public async start(): Promise<void> { public async start(): Promise<void> {
this.loadGroupIds(); this.loadGroupIds();
// tslint:disable: no-floating-promises void this.pollForAllKeys();
this.pollForAllKeys();
} }
public addGroupId(pubkey: PubKey) { public addGroupId(pubkey: PubKey) {
@ -133,7 +131,7 @@ export class SwarmPolling {
const lastMessage = _.last(messages); const lastMessage = _.last(messages);
this.updateLastHash( await this.updateLastHash(
edkey, edkey,
pubkey, pubkey,
lastMessage.hash, lastMessage.hash,
@ -187,10 +185,13 @@ export class SwarmPolling {
const groupPromises = this.groupPubkeys.map(async pk => { const groupPromises = this.groupPubkeys.map(async pk => {
return this.pollOnceForKey(pk, true); return this.pollOnceForKey(pk, true);
}); });
try {
await Promise.all(_.concat(directPromises, groupPromises)); await Promise.all(_.concat(directPromises, groupPromises));
} catch (e) {
setTimeout(this.pollForAllKeys.bind(this), 2000); window.log.warn('pollForAllKeys swallowing exception: ', e);
} finally {
setTimeout(this.pollForAllKeys.bind(this), 2000);
}
} }
private async updateLastHash( private async updateLastHash(

Loading…
Cancel
Save