fix(server): clean up bridge and hybrid shutdown handling

This commit is contained in:
2026-04-06 10:15:37 +00:00
parent a293986d6d
commit d4bad38908
5 changed files with 111 additions and 13 deletions

View File

@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartvpn',
version: '1.19.1',
version: '1.19.2',
description: 'A VPN solution with TypeScript control plane and Rust data plane daemon'
}

View File

@@ -333,17 +333,35 @@ export class VpnServer extends plugins.events.EventEmitter {
/**
* Stop the daemon bridge.
*/
public stop(): void {
public async stop(): Promise<void> {
// Clean up nftables rules
if (this.nftHealthInterval) {
clearInterval(this.nftHealthInterval);
this.nftHealthInterval = undefined;
}
if (this.nft) {
this.nft.cleanup().catch(() => {}); // best-effort cleanup
try {
await this.nft.cleanup();
} catch (e) {
console.warn(`[smartvpn] nftables cleanup failed: ${e}`);
}
this.nft = undefined;
}
// Wait for bridge process to exit (with timeout)
const exitPromise = new Promise<void>((resolve) => {
if (!this.bridge.running) {
resolve();
return;
}
const timeout = setTimeout(() => resolve(), 5000);
this.bridge.once('exit', () => {
clearTimeout(timeout);
resolve();
});
});
this.bridge.stop();
await exitPromise;
}
/**