Skip to content

Commit a5e6ac6

Browse files
committed
fix: restart_iwdp uses -F flag, pkill -x, detached context
- Use -F (short for --no-frontend) flag for ios_webkit_debug_proxy - Use pkill -x for exact binary name match instead of pkill -f - Wait for process to fully exit before restarting - Detach iwdp process from MCP context so it outlives the server
1 parent ab207bf commit a5e6ac6

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

internal/proxy/proxy.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ func IsRunning() bool {
3838
}
3939

4040
// Start launches ios_webkit_debug_proxy as a background process.
41-
func Start(ctx context.Context) error {
42-
cmd := exec.CommandContext(ctx, "ios_webkit_debug_proxy", "--no-frontend")
41+
// Uses a detached context so iwdp outlives the MCP server if needed.
42+
func Start(_ context.Context) error {
43+
cmd := exec.Command("ios_webkit_debug_proxy", "-F")
4344
if err := cmd.Start(); err != nil {
4445
return fmt.Errorf("starting ios_webkit_debug_proxy: %w\nMake sure it is installed: brew install ios-webkit-debug-proxy", err)
4546
}
@@ -70,9 +71,15 @@ func EnsureRunning(ctx context.Context) error {
7071
// Restart kills any existing iwdp process and starts a fresh one.
7172
// Use this when iwdp is in a bad state (e.g., after a WebSocket crash).
7273
func Restart(ctx context.Context) error {
73-
// Best-effort kill — ignore errors if not running
74-
_ = exec.Command("pkill", "-f", "ios_webkit_debug_proxy").Run()
75-
time.Sleep(500 * time.Millisecond)
74+
// Best-effort kill — use exact binary name to avoid matching unrelated processes
75+
_ = exec.Command("pkill", "-x", "ios_webkit_debug_proxy").Run()
76+
// Wait for the process to fully exit and release the port
77+
for i := 0; i < 10; i++ {
78+
time.Sleep(300 * time.Millisecond)
79+
if !IsRunning() {
80+
break
81+
}
82+
}
7683
return Start(ctx)
7784
}
7885

0 commit comments

Comments
 (0)