{"record":{"id":"16269946e9c0bf9a","repo":"xtekky/gpt4free","slug":"timeout-waiting-for-cloudflare-response","errorCode":null,"errorMessage":"Timeout waiting for Cloudflare response","messagePattern":"Timeout waiting for Cloudflare response","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/Cloudflare.py","lineNumber":234,"sourceCode":"            while True:\n                try:\n                    event = await asyncio.wait_for(q.get(), timeout=30.0)\n                    args = event.get(\"args\", [])\n                    if args and args[0].get(\"type\") == \"string\":\n                        val = args[0].get(\"value\", \"\")\n                        if val == last_val:\n                            continue\n                        last_val = val\n                        if val.startswith(\"CF_CHUNK: \"):\n                            yield val[10:]\n                        elif val == \"CF_DONE\":\n                            break\n                        elif val == \"CF_ERROR\":\n                            raise RuntimeError(\n                                \"WebSocket error inside Cloudflare session\"\n                            )\n                except asyncio.TimeoutError:\n                    raise TimeoutError(\"Timeout waiting for Cloudflare response\")\n        finally:\n            session.remove_event_handler(\"Runtime.consoleAPICalled\", q)\n            await session.close()\n","sourceCodeStart":216,"sourceCodeEnd":238,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/Cloudflare.py#L216-L238","documentation":"IsTermuxInstalled runs `pm list packages` via exec and cmd.Output() failed. On Android this means the pm binary was not found on PATH, was not executable from this process context, or exited non-zero; the %w wraps the underlying exec error. Note the function already returns a separate error when GOOS != android, so this one is Android-execution-specific.","triggerScenarios":"Running inside a non-Termux Android context (e.g. a plain adb shell or an app sandbox) where pm is not on PATH; SELinux denying exec of pm; pm exiting non-zero because of a dead package manager session; Termux environment where PATH was reset.","commonSituations":"Testing the Go binary via adb shell instead of inside Termux; CI/emulator images with restricted shells; devices where pm requires a specific user context; PATH stripped by su or a wrapper script.","solutions":["Check the wrapped err: exec.ErrNotFound means PATH lacks pm — use the absolute path /system/bin/pm in the exec.Command call","Confirm you are running inside a proper Android app context (Termux), not a raw adb shell with a minimal PATH","If SELinux is the cause (see logcat), run from the Termux app context where exec of system tools is permitted","Fall back to detecting Termux by filesystem probe (e.g. stat /data/data/com.termux) when pm is unavailable"],"exampleFix":"// before\ncmd := exec.Command(\"pm\", \"list\", \"packages\")\n\n// after\ncmd := exec.Command(\"/system/bin/pm\", \"list\", \"packages\")","handlingStrategy":"fallback","validationCode":"func termuxAvailable() bool {\n    if _, err := exec.LookPath(\"pm\"); err != nil {\n        if _, statErr := os.Stat(\"/system/bin/pm\"); statErr != nil {\n            return false\n        }\n    }\n    if _, err := os.Stat(\"/data/data/com.termux\"); err == nil {\n        return true // filesystem probe works without pm\n    }\n    out, err := exec.Command(\"/system/bin/pm\", \"list\", \"packages\").Output()\n    return err == nil && strings.Contains(string(out), \"com.termux\")\n}","typeGuard":null,"tryCatchPattern":"installed, err := IsTermuxInstalled()\nif err != nil {\n    // do not treat a broken pm as 'no termux'; fall back to filesystem detection\n    installed = termuxAvailable()\n}","preventionTips":["Invoke pm by absolute path /system/bin/pm rather than relying on PATH","Keep a filesystem-based Termux probe as fallback for restricted shells"],"tags":["android","termux","exec","package-manager"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}