fix: 避免识别异常与支付锁泄漏

修复 ASR 取消后的孤立会话、OCR 表格重复及支付锁无法回收的问题,并补充回归测试。
This commit is contained in:
lik
2026-11-08 12:43:06 +08:00
parent 7c4a90c113
commit 84461e9445
6 changed files with 76 additions and 7 deletions
+6 -4
View File
@@ -19,9 +19,11 @@ const payLocks = new Map();
function withPayLock(key, fn) {
const previous = payLocks.get(key) || Promise.resolve();
const current = previous.then(fn, fn);
payLocks.set(key, current.finally(() => {
if (payLocks.get(key) === current) payLocks.delete(key);
}));
const tracked = current.then(
() => { if (payLocks.get(key) === tracked) payLocks.delete(key); },
() => { if (payLocks.get(key) === tracked) payLocks.delete(key); }
);
payLocks.set(key, tracked);
return current;
}
@@ -1242,4 +1244,4 @@ function startPaymentPatrol({ intervalMs = 10 * 60 * 1000 } = {}) {
return patrolTimer;
}
export { HandlerPayment, startPaymentPatrol, runPaymentPatrolOnce };
export { HandlerPayment, startPaymentPatrol, runPaymentPatrolOnce, withPayLock, payLocks };