1
0
forked from Yara724/api

YARA-1056

This commit is contained in:
SepehrYahyaee
2026-07-11 13:16:14 +03:30
parent 7a3ddcc7be
commit 54ae82aa38
2 changed files with 8 additions and 3 deletions

View File

@@ -32,12 +32,17 @@ export class CaptchaChallengeService {
this.captchaService.normalizeAnswer(generated.text), this.captchaService.normalizeAnswer(generated.text),
); );
// expireAt is the MongoDB TTL sentinel. The TTL reaper fires every ~60 s, so
// setting it equal to expiresAt means Mongo can delete the document up to 60 s
// BEFORE the application-level expiry check runs — causing the intermittent
// "captchaId not found" error under load. Adding a 120 s grace buffer ensures
// the document is always present when verify() runs its own expiresAt check.
await this.captchaChallengeDbService.create({ await this.captchaChallengeDbService.create({
captchaId, captchaId,
answerHash, answerHash,
image: generated.image, image: generated.image,
expiresAt: generated.expiresAt, expiresAt: generated.expiresAt,
expireAt: new Date(generated.expiresAt), expireAt: new Date(generated.expiresAt + 120_000),
usedAt: null, usedAt: null,
}); });

View File

@@ -10,8 +10,8 @@ export class CaptchaChallenge {
@Prop({ required: true, unique: true, index: true }) @Prop({ required: true, unique: true, index: true })
captchaId: string; captchaId: string;
@Prop() @Prop({ required: true })
answerHash?: string; answerHash: string;
@Prop({ required: true }) @Prop({ required: true })
image: string; image: string;