make retryInfo optional

This commit is contained in:
Florian Dold 2021-06-11 13:18:33 +02:00
parent e77510106f
commit 7d15ce3d88
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
5 changed files with 17 additions and 7 deletions

View File

@ -185,8 +185,11 @@ export async function runPaymentFaultTest(t: GlobalTestState) {
return; return;
} }
if (faultCount < 3) { if (faultCount < 3) {
console.log(`blocking /deposit request #${faultCount}`);
faultCount++; faultCount++;
ctx.dropResponse = true; ctx.dropResponse = true;
} else {
console.log(`letting through /deposit request #${faultCount}`);
} }
}, },
}); });

View File

@ -1332,7 +1332,7 @@ export interface PurchaseRecord {
abortStatus: AbortStatus; abortStatus: AbortStatus;
payRetryInfo: RetryInfo; payRetryInfo?: RetryInfo;
lastPayError: TalerErrorDetails | undefined; lastPayError: TalerErrorDetails | undefined;

View File

@ -51,6 +51,7 @@ import {
PreparePayResultType, PreparePayResultType,
parsePayUri, parsePayUri,
Logger, Logger,
getDurationRemaining,
} from "@gnu-taler/taler-util"; } from "@gnu-taler/taler-util";
import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto"; import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto";
import { import {
@ -522,10 +523,15 @@ async function incrementPurchasePayRetry(
return; return;
} }
if (!pr.payRetryInfo) { if (!pr.payRetryInfo) {
return; pr.payRetryInfo = initRetryInfo();
} }
pr.payRetryInfo.retryCounter++; pr.payRetryInfo.retryCounter++;
updateRetryInfoTimeout(pr.payRetryInfo); updateRetryInfoTimeout(pr.payRetryInfo);
logger.trace(
`retrying pay in ${
getDurationRemaining(pr.payRetryInfo.nextRetry).d_ms
} ms`,
);
pr.lastPayError = err; pr.lastPayError = err;
await tx.purchases.put(pr); await tx.purchases.put(pr);
}); });
@ -556,7 +562,7 @@ async function resetDownloadProposalRetry(
.runReadWrite(async (tx) => { .runReadWrite(async (tx) => {
const p = await tx.proposals.get(proposalId); const p = await tx.proposals.get(proposalId);
if (p) { if (p) {
p.retryInfo = initRetryInfo(); delete p.retryInfo;
await tx.proposals.put(p); await tx.proposals.put(p);
} }
}); });
@ -1135,7 +1141,7 @@ async function submitPay(
// Hide transient errors. // Hide transient errors.
if ( if (
purchase.payRetryInfo.retryCounter <= 5 && (purchase.payRetryInfo?.retryCounter ?? 0) <= 5 &&
resp.status >= 500 && resp.status >= 500 &&
resp.status <= 599 resp.status <= 599
) { ) {
@ -1214,7 +1220,7 @@ async function submitPay(
); );
// Hide transient errors. // Hide transient errors.
if ( if (
purchase.payRetryInfo.retryCounter <= 5 && (purchase.payRetryInfo?.retryCounter ?? 0) <= 5 &&
resp.status >= 500 && resp.status >= 500 &&
resp.status <= 599 resp.status <= 599
) { ) {

View File

@ -200,10 +200,11 @@ async function gatherPurchasePending(
): Promise<void> { ): Promise<void> {
await tx.purchases.iter().forEach((pr) => { await tx.purchases.iter().forEach((pr) => {
if (pr.paymentSubmitPending && pr.abortStatus === AbortStatus.None) { if (pr.paymentSubmitPending && pr.abortStatus === AbortStatus.None) {
const timestampDue = pr.payRetryInfo?.nextRetry ?? getTimestampNow();
resp.pendingOperations.push({ resp.pendingOperations.push({
type: PendingOperationType.Pay, type: PendingOperationType.Pay,
givesLifeness: true, givesLifeness: true,
timestampDue: pr.payRetryInfo.nextRetry, timestampDue,
isReplay: false, isReplay: false,
proposalId: pr.proposalId, proposalId: pr.proposalId,
retryInfo: pr.payRetryInfo, retryInfo: pr.payRetryInfo,

View File

@ -164,7 +164,7 @@ export interface PendingPayOperation {
type: PendingOperationType.Pay; type: PendingOperationType.Pay;
proposalId: string; proposalId: string;
isReplay: boolean; isReplay: boolean;
retryInfo: RetryInfo; retryInfo?: RetryInfo;
lastError: TalerErrorDetails | undefined; lastError: TalerErrorDetails | undefined;
} }