diff options
author | Florian Dold <florian@dold.me> | 2024-06-16 17:58:34 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-06-16 17:58:34 +0200 |
commit | e00ecc6d717fe9a37e35a95d552ab982808377f8 (patch) | |
tree | c34a18a119b1484ea3b27ed97c696879c2723dec /packages | |
parent | 65f168b4d259603cb9321f19228507875da87038 (diff) | |
download | wallet-core-e00ecc6d717fe9a37e35a95d552ab982808377f8.tar.xz |
wallet-core: process sessions in refresh group sequentially
Otherwise we can easily run in the situation where we make a lot of
crypto and network requests in parallel, never really making progress,
because we go OOM before the results are committed to the DB.
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-wallet-core/src/refresh.ts | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/packages/taler-wallet-core/src/refresh.ts b/packages/taler-wallet-core/src/refresh.ts index cb39e6588..01970f8bc 100644 --- a/packages/taler-wallet-core/src/refresh.ts +++ b/packages/taler-wallet-core/src/refresh.ts @@ -54,7 +54,6 @@ import { makeErrorDetail, NotificationType, RefreshReason, - TalerError, TalerErrorCode, TalerErrorDetail, TalerPreciseTimestamp, @@ -1344,35 +1343,36 @@ export async function processRefreshGroup( throw Error("refresh blocked"); } - // Process refresh sessions of the group in parallel. logger.trace( `processing refresh sessions for ${refreshGroup.oldCoinPubs.length} old coins`, ); let errors: TalerErrorDetail[] = []; let inShutdown = false; - const ps = refreshGroup.oldCoinPubs.map((x, i) => - processRefreshSession(wex, refreshGroupId, i).catch((x) => { + + // Process refresh sessions in sequence. + // In the future, we could parallelize request, in particular when multiple + // exchanges are involved. + // But we need to make sure that we write results to DB with high priority, + // otherwise we run into problems with very large refresh groups, where we'd first + // do many many network requests before even going to the DB. + + for (let i = 0; i < refreshGroup.oldCoinPubs.length; i++) { + try { + await processRefreshSession(wex, refreshGroupId, i); + } catch (x) { if (x instanceof CryptoApiStoppedError) { inShutdown = true; logger.info( "crypto API stopped while processing refresh group, probably the wallet is currently shutting down.", ); - return; - } - if (x instanceof TalerError) { - logger.warn("process refresh session got exception (TalerError)"); - logger.warn(`exc ${x}`); - logger.warn(`exc stack ${x.stack}`); - logger.warn(`error detail: ${j2s(x.errorDetail)}`); - } else { - logger.warn("process refresh session got exception"); - logger.warn(`exc ${x}`); - logger.warn(`exc stack ${x.stack}`); + break; } - errors.push(getErrorDetailFromException(x)); - }), - ); - await Promise.all(ps); + const err = getErrorDetailFromException(x); + logger.warn(`exception in refresh session: ${j2s(err)}`); + errors.push(getErrorDetailFromException(err)); + } + } + if (inShutdown) { return TaskRunResult.finished(); } |