From ae96936a1a520432714a7eb1d9e3980d1c2d95a2 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 3 Apr 2024 16:27:58 +1100 Subject: [PATCH] fix: add logs during polling --- ts/session/apis/snode_api/retrieveRequest.ts | 17 ++++++++--------- ts/session/apis/snode_api/swarmPolling.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/ts/session/apis/snode_api/retrieveRequest.ts b/ts/session/apis/snode_api/retrieveRequest.ts index 31e5827f3..07d646b10 100644 --- a/ts/session/apis/snode_api/retrieveRequest.ts +++ b/ts/session/apis/snode_api/retrieveRequest.ts @@ -1,4 +1,4 @@ -import { omit } from 'lodash'; +import { isArray, omit } from 'lodash'; import { Snode } from '../../../data/data'; import { updateIsOnline } from '../../../state/ducks/onion'; import { doSnodeBatchRequest } from './batchRequest'; @@ -7,6 +7,7 @@ import { SnodeNamespace, SnodeNamespaces } from './namespaces'; import { TTL_DEFAULT } from '../../constants'; import { UserUtils } from '../../utils'; +import { sleepFor } from '../../utils/Promise'; import { RetrieveLegacyClosedGroupSubRequestType, RetrieveSubRequestType, @@ -123,14 +124,12 @@ async function retrieveNextMessages( ); // let exceptions bubble up // no retry for this one as this a call we do every few seconds while polling for messages - - const results = await doSnodeBatchRequest( - retrieveRequestsParams, - targetNode, - 4000, - associatedWith - ); - if (!results || !results.length) { + const timeOutMs = 4 * 1000; + const results = await Promise.race([ + async () => doSnodeBatchRequest(retrieveRequestsParams, targetNode, timeOutMs, associatedWith), + async () => sleepFor(timeOutMs), // just to make sure that we don't hang for more than 4s + ]); + if (!results || !isArray(results) || !results.length) { window?.log?.warn( `_retrieveNextMessages - sessionRpc could not talk to ${targetNode.ip}:${targetNode.port}` ); diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index 4a335dfc6..c43fce899 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -228,12 +228,21 @@ export class SwarmPolling { let resultsFromAllNamespaces: RetrieveMessagesResultsBatched | null; try { + // Note: always print something so we know if the polling is hanging + window.log.info( + `about to pollNodeForKey of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${namespaces} ` + ); resultsFromAllNamespaces = await this.pollNodeForKey( toPollFrom, pubkey, namespaces, !isGroup ); + + // Note: always print something so we know if the polling is hanging + window.log.info( + `pollNodeForKey of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${namespaces} returned: ${resultsFromAllNamespaces?.length}` + ); } catch (e) { window.log.warn( `pollNodeForKey of ${pubkey} namespaces: ${namespaces} failed with: ${e.message}` @@ -475,6 +484,9 @@ export class SwarmPolling { return last(r.messages.messages); }); + window.log.info( + `updating last hashes for ${ed25519Str(pubkey.key)}: ${ed25519Str(snodeEdkey)} ${lastMessages.map(m => m?.hash || '')}` + ); await Promise.all( lastMessages.map(async (lastMessage, index) => { if (!lastMessage) {