{"record":{"id":"ad5fa27a49d57c4f","repo":"xtekky/gpt4free","slug":"websocket-error-ws-exception","errorCode":null,"errorMessage":"WebSocket Error: {ws.exception()}","messagePattern":"WebSocket Error: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/CopilotApp.py","lineNumber":128,"sourceCode":"                    async for msg in ws:\n                        if msg.type == aiohttp.WSMsgType.TEXT:\n                            data = json.loads(msg.data)\n                            event = data.get(\"event\")\n                            if event == \"appendText\":\n                                yield data.get(\"text\", \"\")\n                            elif event == \"citation\":\n                                sources[data.get(\"url\")] = data\n                                yield SourceLink(\n                                    list(sources.keys()).index(data.get(\"url\")),\n                                    data.get(\"url\"),\n                                )\n                            elif event == \"done\":\n                                if sources:\n                                    yield Sources(sources.values())\n                                cls.live += 1\n                                break\n                        elif msg.type == aiohttp.WSMsgType.ERROR:\n                            raise RuntimeError(f\"WebSocket Error: {ws.exception()}\")\n        except Exception as e:\n            cls.live -= 1\n            raise RuntimeError(f\"Error during CopilotApp interaction: {e}\") from e","sourceCodeStart":110,"sourceCodeEnd":131,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/CopilotApp.py#L110-L131","documentation":"While reading the CopilotApp chat WebSocket, aiohttp reported a protocol-level WSMsgType.ERROR. The underlying exception from ws.exception() (connection reset, handshake failure, protocol violation) is embedded in the message. This is a transport-layer failure of the websocket, distinct from application-level error events.","triggerScenarios":"WebSocket connection reset by server or intermediary proxy; TLS/proxy handshake issue after connect; keepalive timeout closing the socket mid-stream; server-side connection drain during maintenance.","commonSituations":"Corporate proxy or HTTP/2-aware middleware terminating long-lived websockets; idle timeout on NAT/firewall; high-latency links dropping the socket; too many concurrent sockets from one client.","solutions":["Check ws.exception() in the message for the precise transport cause","Retry with backoff — transient resets are common for long streams","If behind a proxy, ensure it supports long-lived WebSocket connections or bypass it"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    async for chunk in CopilotApp.create_async_generator(model, messages):\n        yield chunk\nexcept RuntimeError as e:\n    if 'WebSocket Error' in str(e):\n        await asyncio.sleep(2)\n        async for chunk in CopilotApp.create_async_generator(model, messages):\n            yield chunk\n    else:\n        raise","preventionTips":["Use proxies that support long-lived WebSocket connections","Retry transport errors once with backoff before surfacing to users","Keep individual conversations short to reduce exposure to socket drops"],"tags":["websocket","network","copilot","transport"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}