fix(client): Improve IPC client robustness and daemon debug logging; update tests and package metadata
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tspm',
|
||||
version: '3.1.2',
|
||||
version: '3.1.3',
|
||||
description: 'a no fuzz process manager'
|
||||
}
|
||||
|
@@ -43,10 +43,14 @@ export class TspmIpcClient {
|
||||
}
|
||||
|
||||
// Create IPC client
|
||||
const uniqueClientId = `cli-${process.pid}-${Date.now()}-${Math.random()
|
||||
.toString(36)
|
||||
.slice(2, 8)}`;
|
||||
this.ipcClient = plugins.smartipc.SmartIpc.createClient({
|
||||
id: 'tspm-cli',
|
||||
socketPath: this.socketPath,
|
||||
clientId: `cli-${process.pid}`,
|
||||
clientId: uniqueClientId,
|
||||
clientOnly: true,
|
||||
connectRetry: {
|
||||
enabled: true,
|
||||
initialDelay: 100,
|
||||
@@ -54,7 +58,7 @@ export class TspmIpcClient {
|
||||
maxAttempts: 30,
|
||||
totalTimeout: 15000,
|
||||
},
|
||||
registerTimeoutMs: 8000,
|
||||
registerTimeoutMs: 15000,
|
||||
heartbeat: true,
|
||||
heartbeatInterval: 5000,
|
||||
heartbeatTimeout: 20000,
|
||||
@@ -73,9 +77,19 @@ export class TspmIpcClient {
|
||||
this.isConnected = false;
|
||||
});
|
||||
|
||||
console.log('Connected to TSPM daemon');
|
||||
// Reflect connection lifecycle on the client state
|
||||
const markDisconnected = () => {
|
||||
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);
|
||||
|
||||
// connected
|
||||
} catch (error) {
|
||||
console.error('Failed to connect to daemon:', error);
|
||||
// surface meaningful error
|
||||
throw new Error(
|
||||
'Could not connect to TSPM daemon. Please try running "tspm daemon start" or "tspm enable".',
|
||||
);
|
||||
@@ -113,7 +127,15 @@ export class TspmIpcClient {
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
// Don't try to auto-reconnect, just throw the error
|
||||
// If the underlying socket disconnected, mark state and surface error
|
||||
const message = (error as any)?.message || '';
|
||||
if (
|
||||
message.includes('Client is not connected') ||
|
||||
message.includes('ENOTCONN') ||
|
||||
message.includes('ECONNREFUSED')
|
||||
) {
|
||||
this.isConnected = false;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
@@ -56,6 +56,17 @@ export class TspmDaemon {
|
||||
heartbeatThrowOnTimeout: false, // Don't throw, emit events instead
|
||||
});
|
||||
|
||||
// Debug hooks for connection troubleshooting
|
||||
this.ipcServer.on('clientConnect', (clientId: string) => {
|
||||
console.log(`[IPC] client connected: ${clientId}`);
|
||||
});
|
||||
this.ipcServer.on('clientDisconnect', (clientId: string) => {
|
||||
console.log(`[IPC] client disconnected: ${clientId}`);
|
||||
});
|
||||
this.ipcServer.on('error', (err: any) => {
|
||||
console.error('[IPC] server error:', err?.message || err);
|
||||
});
|
||||
|
||||
// Register message handlers
|
||||
this.registerHandlers();
|
||||
|
||||
|
Reference in New Issue
Block a user