Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

use DB time to avoid time diff

Thiago Araujo da Silva529572bae2eb
diff --git a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-dal.ts b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-dal.ts
index b0ae37dde1..3cce2d6dc2 100644
--- a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-dal.ts
+++ b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-dal.ts
@@ -139,11 +139,11 @@ export const auditLogStreamOutboxDALFactory = (db: TDbClient) => {
// Flip them back to 'retry' with nextRetryAt=NOW() so the next debounce-driven
// flush picks them up. Attempts is left unchanged — a stale claim is a worker
// fault, not a delivery failure, and shouldn't burn retry budget.
- const requeueStaleClaims = async (staleBefore: Date): Promise<number> => {
+ const requeueStaleClaims = async (thresholdMs: number): Promise<number> => {
try {
const updated = await db(TableName.AuditLogStreamOutbox)
.where("status", AuditLogStreamOutboxStatus.Processing)
- .andWhere("lockedAt", "<", staleBefore)
+ .andWhereRaw(`"lockedAt" < NOW() - (? || ' milliseconds')::INTERVAL`, [thresholdMs])
.update({
status: AuditLogStreamOutboxStatus.Retry,
nextRetryAt: db.fn.now(),
diff --git a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
index ddb73b00fd..a519b9fd4f 100644
--- a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
+++ b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts
@@ -238,11 +238,10 @@ export const auditLogStreamOutboxServiceFactory = ({
// forever and never re-enter the drain query. Flip them back to 'retry' so
// the next event for that stream picks them up via the normal debounce path.
const sweepStaleClaims = async () => {
- const staleBefore = new Date(Date.now() - STALE_CLAIM_THRESHOLD_MS);
- const recovered = await auditLogStreamOutboxDAL.requeueStaleClaims(staleBefore);
+ const recovered = await auditLogStreamOutboxDAL.requeueStaleClaims(STALE_CLAIM_THRESHOLD_MS);
if (recovered > 0) {
logger.warn(
- `audit-log-stream-outbox: recovered ${recovered} stale claims [staleBefore=${staleBefore.toISOString()}]`
+ `audit-log-stream-outbox: recovered ${recovered} stale claims [thresholdMs=${STALE_CLAIM_THRESHOLD_MS}]`
);
}
};