feat(daemon): Add crash log manager with rotation and integrate crash logging; improve IPC & process listener cleanup
This commit is contained in:
@@ -17,6 +17,9 @@ export class TspmIpcClient {
|
||||
private socketPath: string;
|
||||
private daemonPidFile: string;
|
||||
private isConnected: boolean = false;
|
||||
// Store event handlers for cleanup
|
||||
private heartbeatTimeoutHandler?: () => void;
|
||||
private markDisconnectedHandler?: () => void;
|
||||
|
||||
constructor() {
|
||||
this.socketPath = plugins.path.join(paths.tspmDir, 'tspm.sock');
|
||||
@@ -74,20 +77,21 @@ export class TspmIpcClient {
|
||||
this.isConnected = true;
|
||||
|
||||
// Handle heartbeat timeouts gracefully
|
||||
this.ipcClient.on('heartbeatTimeout', () => {
|
||||
this.heartbeatTimeoutHandler = () => {
|
||||
console.warn('Heartbeat timeout detected, connection may be degraded');
|
||||
this.isConnected = false;
|
||||
});
|
||||
};
|
||||
this.ipcClient.on('heartbeatTimeout', this.heartbeatTimeoutHandler);
|
||||
|
||||
// Reflect connection lifecycle on the client state
|
||||
const markDisconnected = () => {
|
||||
this.markDisconnectedHandler = () => {
|
||||
this.isConnected = false;
|
||||
};
|
||||
// Common lifecycle events
|
||||
this.ipcClient.on('disconnect', markDisconnected as any);
|
||||
this.ipcClient.on('close', markDisconnected as any);
|
||||
this.ipcClient.on('end', markDisconnected as any);
|
||||
this.ipcClient.on('error', markDisconnected as any);
|
||||
this.ipcClient.on('disconnect', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.on('close', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.on('end', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.on('error', this.markDisconnectedHandler as any);
|
||||
|
||||
// connected
|
||||
} catch (error) {
|
||||
@@ -103,6 +107,21 @@ export class TspmIpcClient {
|
||||
*/
|
||||
public async disconnect(): Promise<void> {
|
||||
if (this.ipcClient) {
|
||||
// Remove event listeners before disconnecting
|
||||
if (this.heartbeatTimeoutHandler) {
|
||||
this.ipcClient.removeListener('heartbeatTimeout', this.heartbeatTimeoutHandler);
|
||||
}
|
||||
if (this.markDisconnectedHandler) {
|
||||
this.ipcClient.removeListener('disconnect', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.removeListener('close', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.removeListener('end', this.markDisconnectedHandler as any);
|
||||
this.ipcClient.removeListener('error', this.markDisconnectedHandler as any);
|
||||
}
|
||||
|
||||
// Clear handler references
|
||||
this.heartbeatTimeoutHandler = undefined;
|
||||
this.markDisconnectedHandler = undefined;
|
||||
|
||||
await this.ipcClient.disconnect();
|
||||
this.ipcClient = null;
|
||||
this.isConnected = false;
|
||||
|
Reference in New Issue
Block a user