fix(heartbeat): improve lock heartbeat shutdown handling

This commit is contained in:
2026-05-19 21:57:22 +00:00
parent 87b518ae63
commit a86a004b19
2 changed files with 19 additions and 7 deletions
+6
View File
@@ -3,6 +3,12 @@
## Pending
### Fixes
- improve lock heartbeat shutdown handling (heartbeat)
- Replaces the stop signal promise race with an explicit wake callback for the heartbeat wait loop
- Ensures the heartbeat loop can be interrupted cleanly when stopping without leaving the timer pending
## 2026-05-19 - 1.4.0
### Features
+13 -7
View File
@@ -544,16 +544,22 @@ export class SmartMigration {
private startLockHeartbeat(ledger: Ledger): ILockHeartbeat {
const intervalMs = this.getLockHeartbeatMs();
let stopped = false;
let resolveStop!: () => void;
let wakeWaiter: (() => void) | null = null;
let lockError: SmartMigrationError | null = null;
const stopSignal = new Promise<void>((resolve) => {
resolveStop = resolve;
});
const loopPromise = (async () => {
while (!stopped) {
await Promise.race([this.sleep(intervalMs), stopSignal]);
await new Promise<void>((resolve) => {
const timeout = setTimeout(() => {
wakeWaiter = null;
resolve();
}, intervalMs);
wakeWaiter = () => {
clearTimeout(timeout);
wakeWaiter = null;
resolve();
};
});
if (stopped) {
return;
}
@@ -589,7 +595,7 @@ export class SmartMigration {
}
stopped = true;
resolveStop();
wakeWaiter?.();
await loopPromise;
},
};