mirror of
https://github.com/samsonjs/vibetunnel.git
synced 2026-03-25 09:25:50 +00:00
fix: Improve heartbeat handling and session.json debounce cleanup
- Echo heartbeat messages back to clients for better connection monitoring - Properly clear debounce timer references to prevent memory leaks - Pass client socket to message handler for proper heartbeat responses
This commit is contained in:
parent
646b478075
commit
3b99312fdb
1 changed files with 17 additions and 7 deletions
|
|
@ -719,7 +719,7 @@ export class PtyManager extends EventEmitter {
|
|||
parser.addData(chunk);
|
||||
|
||||
for (const { type, payload } of parser.parseMessages()) {
|
||||
this.handleSocketMessage(session, type, payload);
|
||||
this.handleSocketMessage(session, type, payload, client);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -750,7 +750,12 @@ export class PtyManager extends EventEmitter {
|
|||
/**
|
||||
* Handle incoming socket messages
|
||||
*/
|
||||
private handleSocketMessage(session: PtySession, type: MessageType, payload: Buffer): void {
|
||||
private handleSocketMessage(
|
||||
session: PtySession,
|
||||
type: MessageType,
|
||||
payload: Buffer,
|
||||
client?: net.Socket
|
||||
): void {
|
||||
try {
|
||||
const data = parsePayload(type, payload);
|
||||
|
||||
|
|
@ -773,7 +778,11 @@ export class PtyManager extends EventEmitter {
|
|||
}
|
||||
|
||||
case MessageType.HEARTBEAT:
|
||||
// Echo heartbeat back (could add heartbeat response later)
|
||||
// Echo heartbeat back to the client
|
||||
if (client && !client.destroyed) {
|
||||
const heartbeatFrame = frameMessage(MessageType.HEARTBEAT, Buffer.alloc(0));
|
||||
client.write(heartbeatFrame);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -802,8 +811,9 @@ export class PtyManager extends EventEmitter {
|
|||
|
||||
debounceTimer = setTimeout(() => {
|
||||
this.handleSessionJsonChange(session);
|
||||
// Clear the timer reference after execution
|
||||
// Clear both timer references after execution
|
||||
session.sessionJsonDebounceTimer = null;
|
||||
debounceTimer = null;
|
||||
}, 100);
|
||||
|
||||
// Update the session's timer reference
|
||||
|
|
@ -811,6 +821,9 @@ export class PtyManager extends EventEmitter {
|
|||
}
|
||||
});
|
||||
|
||||
// Store watcher for cleanup BEFORE setting up error handler
|
||||
session.sessionJsonWatcher = watcher;
|
||||
|
||||
// Add error handling for watcher
|
||||
watcher.on('error', (error) => {
|
||||
logger.error(`Session.json watcher failed for ${session.id}:`, error);
|
||||
|
|
@ -823,9 +836,6 @@ export class PtyManager extends EventEmitter {
|
|||
}
|
||||
});
|
||||
|
||||
// Store watcher for cleanup
|
||||
session.sessionJsonWatcher = watcher;
|
||||
|
||||
// Unref the watcher so it doesn't keep the process alive
|
||||
watcher.unref();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue