Skip to content

Commit 2276011

Browse files
authored
Merge pull request #93 from smart-mcp-proxy/fix/tray-startup-timeout-and-output-capture
Fix: Tray startup timeout and output capture race conditions
2 parents fd3dc86 + 1b68bc7 commit 2276011

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

cmd/mcpproxy-tray/internal/monitor/process.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,31 @@ func (pm *ProcessMonitor) setupOutputCapture() error {
371371
return fmt.Errorf("failed to create stderr pipe: %w", err)
372372
}
373373

374+
// Use a WaitGroup to ensure capture goroutines are ready before starting process
375+
var captureReady sync.WaitGroup
376+
captureReady.Add(2) // stdout + stderr
377+
374378
// Start output capture goroutines
375-
go pm.captureOutput(stdoutPipe, &pm.stdoutBuf, "stdout")
376-
go pm.captureOutput(stderrPipe, &pm.stderrBuf, "stderr")
379+
go pm.captureOutput(stdoutPipe, &pm.stdoutBuf, "stdout", &captureReady)
380+
go pm.captureOutput(stderrPipe, &pm.stderrBuf, "stderr", &captureReady)
381+
382+
// Wait for both capture goroutines to be ready
383+
captureReady.Wait()
384+
pm.logger.Debug("Output capture goroutines ready")
377385

378386
return nil
379387
}
380388

381389
// captureOutput captures output from a pipe
382-
func (pm *ProcessMonitor) captureOutput(pipe io.ReadCloser, buf *strings.Builder, streamName string) {
390+
func (pm *ProcessMonitor) captureOutput(pipe io.ReadCloser, buf *strings.Builder, streamName string, ready *sync.WaitGroup) {
383391
defer pipe.Close()
384392

393+
// Signal that this goroutine is ready to read
394+
if ready != nil {
395+
pm.logger.Debug("Output capture goroutine starting", "stream", streamName)
396+
ready.Done()
397+
}
398+
385399
scanner := bufio.NewScanner(pipe)
386400
for scanner.Scan() {
387401
line := scanner.Text()

cmd/mcpproxy-tray/internal/state/states.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ type Info struct {
106106

107107
// GetInfo returns metadata for a given state
108108
func GetInfo(state State) Info {
109-
timeout30s := 30 * time.Second
109+
timeout90s := 90 * time.Second // Must exceed health monitor's readinessTimeout (60s)
110110
timeout5s := 5 * time.Second
111111
timeout10s := 10 * time.Second
112112

@@ -127,7 +127,7 @@ func GetInfo(state State) Info {
127127
Name: StateWaitingForCore,
128128
Description: "Waiting for core to become ready",
129129
UserMessage: "Core starting up...",
130-
Timeout: &timeout30s,
130+
Timeout: &timeout90s, // Increased to 90s to allow Docker isolation startup (health timeout is 60s)
131131
},
132132
StateConnectingAPI: {
133133
Name: StateConnectingAPI,

0 commit comments

Comments
 (0)