From 862ac9a16aa891c26355f9ad5858283c3aa029d6 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 19 Feb 2024 21:13:00 +0100 Subject: wallet-core: safer long-polling We now wait for some time if long-polling returns too early --- packages/taler-wallet-core/src/withdraw.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'packages/taler-wallet-core/src/withdraw.ts') diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts index 9cf1ad36d..bfcf23588 100644 --- a/packages/taler-wallet-core/src/withdraw.ts +++ b/packages/taler-wallet-core/src/withdraw.ts @@ -911,6 +911,7 @@ async function processPlanchetExchangeBatchRequest( ws: InternalWalletState, wgContext: WithdrawalGroupContext, args: WithdrawalRequestBatchArgs, + cancellationToken: CancellationToken, ): Promise { const withdrawalGroup: WithdrawalGroupRecord = wgContext.wgRecord; logger.info( @@ -997,6 +998,8 @@ async function processPlanchetExchangeBatchRequest( const resp = await ws.http.fetch(reqUrl, { method: "POST", body: batchReq, + cancellationToken, + timeout: Duration.fromSpec({ seconds: 40 }), }); if (resp.status === HttpStatusCode.UnavailableForLegalReasons) { await handleKycRequired(ws, withdrawalGroup, resp, 0, requestCoinIdxs); @@ -1300,7 +1303,7 @@ async function processQueryReserve( `got reserve status error, EC=${result.talerErrorResponse.code}`, ); if (resp.status === HttpStatusCode.NotFound) { - return TaskRunResult.backoff(); + return TaskRunResult.longpollReturnedPending(); } else { throwUnexpectedRequestError(resp, result.talerErrorResponse); } @@ -1491,6 +1494,7 @@ async function processWithdrawalGroupPendingKyc( async function processWithdrawalGroupPendingReady( ws: InternalWalletState, withdrawalGroup: WithdrawalGroupRecord, + cancellationToken: CancellationToken, ): Promise { const { withdrawalGroupId } = withdrawalGroup; const transactionId = constructTransactionIdentifier({ @@ -1553,10 +1557,15 @@ async function processWithdrawalGroupPendingReady( const maxBatchSize = 100; for (let i = 0; i < numTotalCoins; i += maxBatchSize) { - const resp = await processPlanchetExchangeBatchRequest(ws, wgContext, { - batchSize: maxBatchSize, - coinStartIndex: i, - }); + const resp = await processPlanchetExchangeBatchRequest( + ws, + wgContext, + { + batchSize: maxBatchSize, + coinStartIndex: i, + }, + cancellationToken, + ); let work: Promise[] = []; work = []; for (let j = 0; j < resp.coinIdxs.length; j++) { @@ -1688,7 +1697,11 @@ export async function processWithdrawalGroup( ); case WithdrawalGroupStatus.PendingReady: // Continue with the actual withdrawal! - return await processWithdrawalGroupPendingReady(ws, withdrawalGroup); + return await processWithdrawalGroupPendingReady( + ws, + withdrawalGroup, + cancellationToken, + ); case WithdrawalGroupStatus.AbortingBank: return await processWithdrawalGroupAbortingBank(ws, withdrawalGroup); case WithdrawalGroupStatus.AbortedBank: @@ -2265,8 +2278,7 @@ async function processReserveBankStatus( } if (!status.transfer_done) { - // FIXME: This is a long-poll result - return TaskRunResult.backoff(); + return TaskRunResult.longpollReturnedPending(); } const transitionInfo = await ws.db.runReadWriteTx( -- cgit v1.2.3