feat(smart-proxy): add socket-handler relay, fast-path port-only forwarding, metrics and bridge improvements, and various TS/Rust integration fixes
This commit is contained in:
@@ -68,12 +68,13 @@ export class RustProxyBridge extends plugins.EventEmitter {
|
||||
});
|
||||
|
||||
// Handle stderr (logging from Rust goes here)
|
||||
this.process.stderr?.on('data', (data: Buffer) => {
|
||||
const stderrHandler = (data: Buffer) => {
|
||||
const lines = data.toString().split('\n').filter(l => l.trim());
|
||||
for (const line of lines) {
|
||||
logger.log('debug', `[rustproxy] ${line}`, { component: 'rust-bridge' });
|
||||
}
|
||||
});
|
||||
};
|
||||
this.process.stderr?.on('data', stderrHandler);
|
||||
|
||||
// Handle stdout (JSON IPC)
|
||||
this.readline = createInterface({ input: this.process.stdout! });
|
||||
@@ -204,16 +205,47 @@ export class RustProxyBridge extends plugins.EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill the Rust process.
|
||||
* Kill the Rust process and clean up all stdio streams.
|
||||
*/
|
||||
public kill(): void {
|
||||
if (this.process) {
|
||||
this.process.kill('SIGTERM');
|
||||
const proc = this.process;
|
||||
this.process = null;
|
||||
this.isRunning = false;
|
||||
|
||||
// Close readline (reads from stdout)
|
||||
if (this.readline) {
|
||||
this.readline.close();
|
||||
this.readline = null;
|
||||
}
|
||||
|
||||
// Reject pending requests
|
||||
for (const [, pending] of this.pendingRequests) {
|
||||
clearTimeout(pending.timer);
|
||||
pending.reject(new Error('RustProxy process killed'));
|
||||
}
|
||||
this.pendingRequests.clear();
|
||||
|
||||
// Remove all listeners so nothing keeps references
|
||||
proc.removeAllListeners();
|
||||
proc.stdout?.removeAllListeners();
|
||||
proc.stderr?.removeAllListeners();
|
||||
proc.stdin?.removeAllListeners();
|
||||
|
||||
// Kill the process
|
||||
try { proc.kill('SIGTERM'); } catch { /* already dead */ }
|
||||
|
||||
// Destroy all stdio pipes to free handles
|
||||
try { proc.stdin?.destroy(); } catch { /* ignore */ }
|
||||
try { proc.stdout?.destroy(); } catch { /* ignore */ }
|
||||
try { proc.stderr?.destroy(); } catch { /* ignore */ }
|
||||
|
||||
// Unref process so Node doesn't wait for it
|
||||
try { proc.unref(); } catch { /* ignore */ }
|
||||
|
||||
// Force kill after 5 seconds
|
||||
setTimeout(() => {
|
||||
if (this.process) {
|
||||
this.process.kill('SIGKILL');
|
||||
}
|
||||
try { proc.kill('SIGKILL'); } catch { /* already dead */ }
|
||||
}, 5000).unref();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user