fix: remove stabilization delay and fitAddon.fit() call
The WebSocket was closing exactly 100ms after switchToTerminal completed, which correlated with the setTimeout(fitAddon.fit(), 100) call. Hypothesis: The fitAddon.fit() call or the 100ms delay is causing the WebSocket to close through an unknown mechanism (possibly triggering browser GC, event loop blocking, or some resource cleanup). Changes: - Removed 100ms stabilization delay in launchCommand - Disabled fitAddon.fit() call in switchToTerminal This should prevent the WebSocket closure and allow commands to be sent.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -701,9 +701,8 @@ class TerminalManager {
|
||||
|
||||
this.debugLog('CMD', `Terminal ${terminalId} is ready!`);
|
||||
|
||||
// Small delay to ensure WebSocket is stable after switching terminals
|
||||
this.debugLog('CMD', `Waiting 100ms for WebSocket to stabilize...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
// NO DELAY - send command immediately to avoid WebSocket closure
|
||||
this.debugLog('CMD', `Sending command immediately without delay...`);
|
||||
|
||||
const terminal = this.terminals.get(terminalId);
|
||||
if (!terminal) {
|
||||
@@ -728,13 +727,7 @@ class TerminalManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if WebSocket has any buffered amount (indicating pending sends)
|
||||
if (terminal.ws.bufferedAmount > 0) {
|
||||
this.debugLog('CMD', `WebSocket has ${terminal.ws.bufferedAmount} bytes buffered, waiting...`);
|
||||
await new Promise(resolve => setTimeout(resolve, 200));
|
||||
}
|
||||
|
||||
// Send command to terminal
|
||||
// Send command to terminal immediately
|
||||
const message = JSON.stringify({
|
||||
type: 'input',
|
||||
data: command
|
||||
@@ -1167,19 +1160,20 @@ class TerminalManager {
|
||||
this.debugLog('INIT', `Terminal ${terminalId} already in map, skipping initialization`);
|
||||
}
|
||||
|
||||
// Fit terminal
|
||||
// Fit terminal - DISABLED to avoid WebSocket closure issue
|
||||
const terminal = this.terminals.get(terminalId);
|
||||
if (terminal && terminal.fitAddon) {
|
||||
this.debugLog('INIT', `Calling fitAddon.fit() for ${terminalId} in 100ms...`);
|
||||
setTimeout(() => {
|
||||
this.debugLog('INIT', `Executing fitAddon.fit() for ${terminalId}`);
|
||||
try {
|
||||
terminal.fitAddon.fit();
|
||||
this.debugLog('INIT', `fitAddon.fit() completed for ${terminalId}`);
|
||||
} catch (error) {
|
||||
this.debugLog('ERROR', `fitAddon.fit() failed for ${terminalId}`, { error: error.message });
|
||||
}
|
||||
}, 100);
|
||||
this.debugLog('INIT', `Skipping fitAddon.fit() for ${terminalId} to avoid WebSocket closure`);
|
||||
// TODO: Investigate why fitAddon.fit() causes WebSocket to close
|
||||
// setTimeout(() => {
|
||||
// this.debugLog('INIT', `Executing fitAddon.fit() for ${terminalId}`);
|
||||
// try {
|
||||
// terminal.fitAddon.fit();
|
||||
// this.debugLog('INIT', `fitAddon.fit() completed for ${terminalId}`);
|
||||
// } catch (error) {
|
||||
// this.debugLog('ERROR', `fitAddon.fit() failed for ${terminalId}`, { error: error.message });
|
||||
// }
|
||||
// }, 100);
|
||||
} else {
|
||||
this.debugLog('INIT', `No fitAddon for terminal ${terminalId} (terminal=${!!terminal}, fitAddon=${!!terminal?.fitAddon})`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user