fix(core): Improve heartbeat handling and transport routing; forward heartbeat timeout events; include clientId routing and probe improvements

This commit is contained in:
2025-08-26 12:32:28 +00:00
parent 32f3c63fca
commit a0638b5364
7 changed files with 148 additions and 34 deletions

View File

@@ -75,7 +75,10 @@ export class IpcClient extends plugins.EventEmitter {
clientId: this.clientId,
metadata: this.options.metadata
},
{ timeout: registerTimeoutMs }
{
timeout: registerTimeoutMs,
headers: { clientId: this.clientId } // Include clientId in headers for proper routing
}
);
if (!response.success) {
@@ -194,10 +197,20 @@ export class IpcClient extends plugins.EventEmitter {
this.emit('disconnect', reason);
});
this.channel.on('error', (error) => {
this.channel.on('error', (error: any) => {
// If heartbeat timeout and configured not to throw, convert to heartbeatTimeout event
if (error && error.message === 'Heartbeat timeout' && this.options.heartbeatThrowOnTimeout === false) {
this.emit('heartbeatTimeout', error);
return;
}
this.emit('error', error);
});
this.channel.on('heartbeatTimeout', (error) => {
// Forward heartbeatTimeout event (when heartbeatThrowOnTimeout is false)
this.emit('heartbeatTimeout', error);
});
this.channel.on('reconnecting', (info) => {
this.emit('reconnecting', info);
});