fix(server): clean up bridge and hybrid shutdown handling
This commit is contained in:
@@ -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'
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user