From 421e613f92b80c81c856d6b074aa160e80e38e3d Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Aug 2020 16:27:20 +0530 Subject: throttling diagnostics and request timeouts --- .../taler-wallet-core/src/operations/refresh.ts | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/refresh.ts') diff --git a/packages/taler-wallet-core/src/operations/refresh.ts b/packages/taler-wallet-core/src/operations/refresh.ts index 430675328..89cc3af43 100644 --- a/packages/taler-wallet-core/src/operations/refresh.ts +++ b/packages/taler-wallet-core/src/operations/refresh.ts @@ -42,7 +42,7 @@ import { import { guardOperationException } from "./errors"; import { NotificationType } from "../types/notifications"; import { getRandomBytes, encodeCrock } from "../crypto/talerCrypto"; -import { getTimestampNow } from "../util/time"; +import { getTimestampNow, Duration } from "../util/time"; import { readSuccessResponseJsonOrThrow, HttpResponse } from "../util/http"; import { codecForExchangeMeltResponse, @@ -211,6 +211,10 @@ async function refreshCreateSession( ws.notify({ type: NotificationType.RefreshStarted }); } +function getRefreshRequestTimeout(rg: RefreshGroupRecord): Duration { + return { d_ms: 5000 }; +} + async function refreshMelt( ws: InternalWalletState, refreshGroupId: string, @@ -249,12 +253,11 @@ async function refreshMelt( }; logger.trace(`melt request for coin:`, meltReq); - const resp = await ws.runSequentialized( - [EXCHANGE_COINS_LOCK], - async () => { - return await ws.http.postJson(reqUrl.href, meltReq); - }, - ); + const resp = await ws.runSequentialized([EXCHANGE_COINS_LOCK], async () => { + return await ws.http.postJson(reqUrl.href, meltReq, { + timeout: getRefreshRequestTimeout(refreshGroup), + }); + }); const meltResponse = await readSuccessResponseJsonOrThrow( resp, @@ -346,12 +349,11 @@ async function refreshReveal( refreshSession.exchangeBaseUrl, ); - const resp = await ws.runSequentialized( - [EXCHANGE_COINS_LOCK], - async () => { - return await ws.http.postJson(reqUrl.href, req); - }, - ); + const resp = await ws.runSequentialized([EXCHANGE_COINS_LOCK], async () => { + return await ws.http.postJson(reqUrl.href, req, { + timeout: getRefreshRequestTimeout(refreshGroup), + }); + }); const reveal = await readSuccessResponseJsonOrThrow( resp, -- cgit v1.2.3