mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-03 22:19:42 +02:00
fix: improve reliability and performance across session management
- Add state store flush on shutdown to prevent data loss from debounced saves - Add error handling in session exit handler to ensure cleanup always runs - Add 5s timeout to all TUI execSync calls to prevent hangs - Cache screen -ls output with 100ms TTL (90% reduction in execSync calls) - Add token pre-check to skip expensive regex when "token" not in data Based on findings from security, performance, and reliability analysis. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+20
-8
@@ -1051,15 +1051,24 @@ export class WebServer extends EventEmitter {
|
||||
});
|
||||
|
||||
session.on('exit', (code) => {
|
||||
this.broadcast('session:exit', { id: session.id, code });
|
||||
this.broadcast('session:updated', session.toDetailedState());
|
||||
// Wrap in try/catch to ensure cleanup always happens
|
||||
try {
|
||||
this.broadcast('session:exit', { id: session.id, code });
|
||||
this.broadcast('session:updated', session.toDetailedState());
|
||||
} catch (err) {
|
||||
console.error(`[Server] Error broadcasting session exit for ${session.id}:`, err);
|
||||
}
|
||||
|
||||
// Clean up respawn controller when session exits (stop + remove listeners)
|
||||
const controller = this.respawnControllers.get(session.id);
|
||||
if (controller) {
|
||||
controller.stop();
|
||||
controller.removeAllListeners();
|
||||
this.respawnControllers.delete(session.id);
|
||||
// Always clean up respawn controller, even if broadcast failed
|
||||
try {
|
||||
const controller = this.respawnControllers.get(session.id);
|
||||
if (controller) {
|
||||
controller.stop();
|
||||
controller.removeAllListeners();
|
||||
this.respawnControllers.delete(session.id);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`[Server] Error cleaning up respawn controller for ${session.id}:`, err);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1609,6 +1618,9 @@ export class WebServer extends EventEmitter {
|
||||
await this.cleanupSession(sessionId, false);
|
||||
}
|
||||
|
||||
// Flush state store to prevent data loss from debounced saves
|
||||
this.store.flushAll();
|
||||
|
||||
await this.app.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user