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
@@ -68,7 +68,9 @@ export type HookSessionDeps = {
|
||||
*
|
||||
* Emitted events:
|
||||
* 'login' (uin, packetSender) — real-UIN login detected
|
||||
* 'disconnected' (wasLoggedIn) — connection dropped or torn down
|
||||
* 'disconnected' (wasLoggedIn) — connection dropped, torn down, or
|
||||
* dispose() of a logged-in session
|
||||
* (process shutdown uses this path)
|
||||
* 'receive-health-changed' (healthy) — combined receive/request path health changed
|
||||
* 'status-changed' (status, error) — status field mutated
|
||||
* 'disposed' () — session stopped tracking this PID
|
||||
@@ -237,8 +239,13 @@ export class HookSession extends EventEmitter {
|
||||
|
||||
dispose(): void {
|
||||
if (this.disposed) return;
|
||||
const wasLoggedIn = this.loggedIn;
|
||||
this.disposed = true;
|
||||
this.tearDownClient();
|
||||
// Process shutdown must take the same PID-detach path as a live drop.
|
||||
// tearDownClient strips the pipe client first, so this emit is the only
|
||||
// disconnected edge HookManager will see.
|
||||
if (wasLoggedIn) this.emit('disconnected', true);
|
||||
this.removeAllListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -644,6 +644,40 @@ describe('HookSession — process gone', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('HookSession — dispose', () => {
|
||||
it('emits disconnected(true) while logged in so BridgeManager can detach the PID', async () => {
|
||||
const ctx = makeSession({ pipeLive: true });
|
||||
const discSpy = vi.fn();
|
||||
ctx.session.on('disconnected', discSpy);
|
||||
|
||||
await ctx.session.load();
|
||||
ctx.session.onPipeUp();
|
||||
await flush();
|
||||
ctx.currentClient().fireLogin('10001');
|
||||
|
||||
ctx.session.dispose();
|
||||
|
||||
expect(discSpy).toHaveBeenCalledOnce();
|
||||
expect(discSpy).toHaveBeenCalledWith(true);
|
||||
expect(ctx.session.isDisposed).toBe(true);
|
||||
});
|
||||
|
||||
it('does not emit disconnected when disposed before login', async () => {
|
||||
const ctx = makeSession({ pipeLive: true });
|
||||
const discSpy = vi.fn();
|
||||
ctx.session.on('disconnected', discSpy);
|
||||
|
||||
await ctx.session.load();
|
||||
ctx.session.onPipeUp();
|
||||
await flush();
|
||||
|
||||
ctx.session.dispose();
|
||||
|
||||
expect(discSpy).not.toHaveBeenCalled();
|
||||
expect(ctx.session.isDisposed).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('HookSession — refresh drift fix', () => {
|
||||
// refresh while the pipe is down on a connected-but-never-logged-in
|
||||
// session now reports 'connecting' (matching what onPipeDown gives for the
|
||||
|
||||
Reference in new issue
Block a user