fix(heartbeat): improve lock heartbeat shutdown handling
This commit is contained in:
@@ -3,6 +3,12 @@
|
|||||||
## Pending
|
## 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
|
## 2026-05-19 - 1.4.0
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
@@ -544,16 +544,22 @@ export class SmartMigration {
|
|||||||
private startLockHeartbeat(ledger: Ledger): ILockHeartbeat {
|
private startLockHeartbeat(ledger: Ledger): ILockHeartbeat {
|
||||||
const intervalMs = this.getLockHeartbeatMs();
|
const intervalMs = this.getLockHeartbeatMs();
|
||||||
let stopped = false;
|
let stopped = false;
|
||||||
let resolveStop!: () => void;
|
let wakeWaiter: (() => void) | null = null;
|
||||||
let lockError: SmartMigrationError | null = null;
|
let lockError: SmartMigrationError | null = null;
|
||||||
|
|
||||||
const stopSignal = new Promise<void>((resolve) => {
|
|
||||||
resolveStop = resolve;
|
|
||||||
});
|
|
||||||
|
|
||||||
const loopPromise = (async () => {
|
const loopPromise = (async () => {
|
||||||
while (!stopped) {
|
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) {
|
if (stopped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -589,7 +595,7 @@ export class SmartMigration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stopped = true;
|
stopped = true;
|
||||||
resolveStop();
|
wakeWaiter?.();
|
||||||
await loopPromise;
|
await loopPromise;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user