{"record":{"id":"67311c7e8f028206","repo":"flipped-aurora/gin-vue-admin","slug":"mcp-s-67311c","errorCode":null,"errorMessage":"MCP 独立进程已退出，请查看日志: %s","messagePattern":"MCP 独立进程已退出，请查看日志: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/standalone_manager.go","lineNumber":287,"sourceCode":"func waitForManagedProcess(ctx context.Context, meta *managedProcessMeta) (ManagedStandaloneStatus, error) {\n\tdeadline := time.NewTimer(mcpStartWaitTimeout)\n\tticker := time.NewTicker(300 * time.Millisecond)\n\tdefer deadline.Stop()\n\tdefer ticker.Stop()\n\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn GetManagedStandaloneStatus(context.Background()), ctx.Err()\n\t\tcase <-deadline.C:\n\t\t\treturn GetManagedStandaloneStatus(context.Background()), fmt.Errorf(\"等待 MCP 独立服务启动超时，请查看日志: %s\", meta.LogPath)\n\t\tcase <-ticker.C:\n\t\t\tcurrent := GetManagedStandaloneStatus(context.Background())\n\t\t\tif current.Reachable {\n\t\t\t\treturn current, nil\n\t\t\t}\n\t\t\tif meta.PID > 0 && !processExists(meta.PID) {\n\t\t\t\treturn current, fmt.Errorf(\"MCP 独立进程已退出，请查看日志: %s\", meta.LogPath)\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc resolveManagedStartCommand() (string, []string, string, string, error) {\n\tserverRoot := resolveMCPServerRoot()\n\tif serverRoot == \"\" {\n\t\treturn \"\", nil, \"\", \"\", errors.New(\"未找到 server 根目录，无法启动 MCP 独立服务\")\n\t}\n\n\tconfigPath, err := resolveMCPConfigPath(serverRoot)\n\tif err != nil {\n\t\treturn \"\", nil, \"\", \"\", err\n\t}\n\n\tif explicit := strings.TrimSpace(os.Getenv(\"GVA_MCP_BIN\")); explicit != \"\" {\n\t\tif !fileExists(explicit) {","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/standalone_manager.go#L269-L305","documentation":"waitForManagedProcess detects that the spawned standalone MCP process exited (its recorded PID no longer exists) while still unreachable, before the start deadline expired. This is an early-exit fast-fail so developers don't wait the full timeout; the log path is included for diagnosis.","triggerScenarios":"Process starts then crashes during initialization: panic in config parsing, failed DB/Redis connection with os.Exit, missing env vars, port already in use causing immediate exit — detected when processExists(meta.PID) returns false on a ticker tick.","commonSituations":"Config file deleted/renamed after spawn; port conflict with another service; incompatible config schema after upgrade; OOM-killer terminating the process; missing runtime dependencies (CGO libs).","solutions":["Read the log file at meta.LogPath — the crash reason (panic, connection refused, port in use) is captured there since stdout/stderr go to the log.","Fix the root cause: free the port, correct the config, restore env/dependencies.","Re-run StartManagedStandalone after fixing; the manager will spawn a fresh process.","If OOM is suspected, check dmesg/journal and increase memory limits."],"exampleFix":"// before (guessing)\nStartManagedStandalone(ctx)\n// after (diagnose first)\ncat /path/to/mcp.log   # path shown in the error\nss -ltnp | grep <port> # confirm no port conflict\nGVA_MCP_BIN=$(pwd)/mcp StartManagedStandalone(ctx)","handlingStrategy":"try-catch","validationCode":"// after a crash, inspect the log before restarting\nif logs, err := os.ReadFile(meta.LogPath); err == nil {\n    if strings.Contains(string(logs), \"panic\") {\n        return fmt.Errorf(\"mcp binary panics on boot; fix before restart\")\n    }\n}","typeGuard":null,"tryCatchPattern":"status, err := StartManagedStandalone(ctx)\nif err != nil && strings.Contains(err.Error(), \"已退出\") {\n    tail, _ := os.ReadFile(meta.LogPath)\n    log.Printf(\"standalone exited; log tail: %s\", tail)\n    return err // do not hot-retry a crashing binary\n}","preventionTips":["Never hot-retry StartManagedStandalone without reading the log — a crash loop will follow.","Validate the config file (path, schema, port) before each start.","Ensure required env vars and runtime libs are present in the deployment image.","Set memory limits above the process's needs to avoid OOM kills."],"tags":["process-crash","mcp","startup-failure"],"backgroundTag":"process-exited-unexpectedly","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}