From f75f63e4e9779c15a607ec7bc11ddca76d2a2f10 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 4 Oct 2021 10:57:52 +1100 Subject: [PATCH] handle 421 on sending delete_all --- ts/session/snode_api/lokiRpc.ts | 11 ++++++++++- ts/session/snode_api/onions.ts | 5 ++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ts/session/snode_api/lokiRpc.ts b/ts/session/snode_api/lokiRpc.ts index c5a2e5445..173e78bc9 100644 --- a/ts/session/snode_api/lokiRpc.ts +++ b/ts/session/snode_api/lokiRpc.ts @@ -1,8 +1,14 @@ import { default as insecureNodeFetch } from 'node-fetch'; +import pRetry from 'p-retry'; import { Snode } from '../../data/data'; import { getStoragePubKey } from '../types'; -import { lokiOnionFetch, snodeHttpsAgent, SnodeResponse } from './onions'; +import { + ERROR_421_HANDLED_RETRY_REQUEST, + lokiOnionFetch, + snodeHttpsAgent, + SnodeResponse, +} from './onions'; interface FetchOptions { method: string; @@ -81,6 +87,9 @@ async function lokiFetch({ if (e.code === 'ENOTFOUND') { throw new window.textsecure.NotFoundError('Failed to resolve address', e); } + if (e.message === ERROR_421_HANDLED_RETRY_REQUEST) { + throw new pRetry.AbortError(ERROR_421_HANDLED_RETRY_REQUEST); + } throw e; } } diff --git a/ts/session/snode_api/onions.ts b/ts/session/snode_api/onions.ts index f4a4c1e04..72611fe3a 100644 --- a/ts/session/snode_api/onions.ts +++ b/ts/session/snode_api/onions.ts @@ -494,6 +494,9 @@ export async function processOnionResponse({ } } +export const ERROR_421_HANDLED_RETRY_REQUEST = + '421 handled. Retry this request with a new targetNode'; + export const snodeHttpsAgent = new https.Agent({ rejectUnauthorized: false, }); @@ -561,7 +564,7 @@ async function handle421InvalidSwarm({ await Onions.incrementBadSnodeCountOrDrop({ snodeEd25519, associatedWith }); // this is important we throw so another retry is made and we exit the handling of that reponse - throw new pRetry.AbortError(exceptionMessage); + throw new pRetry.AbortError(ERROR_421_HANDLED_RETRY_REQUEST); } /**