fix(core): close Bridges on exit without a fake offline
This commit is contained in:
9 files changed
+92
-8
No files matched your search
@@ -118,14 +118,17 @@ async function main() {
|
||||
exitCode = 1;
|
||||
log.error('notification shutdown failed: %s', error instanceof Error ? (error.stack ?? error.message) : String(error));
|
||||
}
|
||||
try { hookManager.dispose(); } catch (error) {
|
||||
exitCode = 1;
|
||||
log.error('hook shutdown failed: %s', error instanceof Error ? (error.stack ?? error.message) : String(error));
|
||||
}
|
||||
// Observers go deaf before Hook teardown. Hook dispose then emits the
|
||||
// same disconnected → PID detach → Bridge closed path as a live drop;
|
||||
// those closed edges must not look like a runtime offline.
|
||||
try { stateWiring.dispose(); } catch (error) {
|
||||
exitCode = 1;
|
||||
log.error('state wiring shutdown failed: %s', error instanceof Error ? (error.stack ?? error.message) : String(error));
|
||||
}
|
||||
try { hookManager.dispose(); } catch (error) {
|
||||
exitCode = 1;
|
||||
log.error('hook shutdown failed: %s', error instanceof Error ? (error.stack ?? error.message) : String(error));
|
||||
}
|
||||
await closeLogger();
|
||||
process.exit(exitCode);
|
||||
};
|
||||
|
||||
@@ -74,6 +74,7 @@ export class NotificationManager {
|
||||
private readonly nicknames = new Map<string, string>();
|
||||
private readonly history: DeliveryRecord[] = [];
|
||||
private readonly historyLimit: number;
|
||||
private disposed = false;
|
||||
|
||||
constructor(deps: NotificationManagerDeps) {
|
||||
this.deps = deps;
|
||||
@@ -88,11 +89,13 @@ export class NotificationManager {
|
||||
}
|
||||
|
||||
handleOnline(uin: string, nickname?: string): void {
|
||||
if (this.disposed) return;
|
||||
if (nickname) this.nicknames.set(uin, nickname);
|
||||
this.apply(uin, this.machine.onOnline(uin));
|
||||
}
|
||||
|
||||
handleOffline(uin: string, nickname?: string): void {
|
||||
if (this.disposed) return;
|
||||
if (nickname) this.nicknames.set(uin, nickname);
|
||||
this.apply(uin, this.machine.onOffline(uin, this.debounceSeconds()));
|
||||
}
|
||||
@@ -221,6 +224,8 @@ export class NotificationManager {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this.disposed) return;
|
||||
this.disposed = true;
|
||||
for (const timer of this.timers.values()) clearTimeout(timer);
|
||||
this.timers.clear();
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
* listeners directly so `qq-list` + `connections` invalidate at the right
|
||||
* moment without modifying BridgeManager.
|
||||
*
|
||||
* `dispose()` unwires everything so a test (or a future hot-reload) can
|
||||
* recreate the wiring without leaking listeners.
|
||||
* `dispose()` sets a latch and neuters the bus. BridgeManager listeners stay
|
||||
* attached; further session edges publish nothing. Process shutdown disposes
|
||||
* this wiring before Hook teardown so exit-time closed is not a WebUI invalidate.
|
||||
*/
|
||||
|
||||
import { StateBus } from './state-bus';
|
||||
|
||||
Reference in new issue
Block a user