Fix konzola: race condition PTY + logging start/finish
- Ne briše ptySess iz sesije po završetku — WS handler ga koristi za replay - WS handler šalje close frame kad proces završi - Logovanje: PTY spawned (PID) + PTY finished (status) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
64df1e784c
commit
fa8aa59b29
@ -3,6 +3,7 @@ package server
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -157,9 +158,11 @@ func cleanEnv() []string {
|
|||||||
func (s *Server) runCommand(session *sessionState, command, execID string) {
|
func (s *Server) runCommand(session *sessionState, command, execID string) {
|
||||||
ptySess, err := spawnConsolePTY(s.projectRoot(), command)
|
ptySess, err := spawnConsolePTY(s.projectRoot(), command)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("PTY spawn error for %s: %v", execID, err)
|
||||||
s.finishSession(session, execID, "error")
|
s.finishSession(session, execID, "error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("PTY spawned for %s (PID %d)", execID, ptySess.Cmd.Process.Pid)
|
||||||
|
|
||||||
session.mu.Lock()
|
session.mu.Lock()
|
||||||
session.cmd = ptySess.Cmd
|
session.cmd = ptySess.Cmd
|
||||||
@ -173,10 +176,11 @@ func (s *Server) runCommand(session *sessionState, command, execID string) {
|
|||||||
if ptySess.Cmd.ProcessState != nil && !ptySess.Cmd.ProcessState.Success() {
|
if ptySess.Cmd.ProcessState != nil && !ptySess.Cmd.ProcessState.Success() {
|
||||||
status = "error"
|
status = "error"
|
||||||
}
|
}
|
||||||
|
log.Printf("PTY finished for %s (status: %s)", execID, status)
|
||||||
|
|
||||||
session.mu.Lock()
|
// Note: we do NOT clear session.ptySess here — the WS handler
|
||||||
session.ptySess = nil
|
// needs it for replay buffer even after the process exits.
|
||||||
session.mu.Unlock()
|
// It gets replaced when a new command starts.
|
||||||
|
|
||||||
s.finishSession(session, execID, status)
|
s.finishSession(session, execID, status)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -113,6 +113,10 @@ connected:
|
|||||||
case writeCh <- []byte("\r\n\033[33m[Sesija završena]\033[0m\r\n"):
|
case writeCh <- []byte("\r\n\033[33m[Sesija završena]\033[0m\r\n"):
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
// Give browser time to receive the message, then close
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
conn.WriteMessage(websocket.CloseMessage,
|
||||||
|
websocket.FormatCloseMessage(websocket.CloseNormalClosure, "done"))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// WebSocket → PTY (read pump)
|
// WebSocket → PTY (read pump)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user