python
network_error
ai_generated
true
starlette.requests.ClientDisconnect:客户端断开连接
starlette.requests.ClientDisconnect: Client disconnected
ID: python/starlette-jsondecodeerror
80%修复率
86%置信度
0证据数
2025-03-15首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 0.30.x | active | — | — | — |
| 0.40.x | active | — | — | — |
根因分析
客户端在服务器读取完整请求体之前关闭了连接。
English
The client closed the connection before the server could read the full request body.
解决方案
-
90% 成功率
try: await request.json() except ClientDisconnect: return JSONResponse(status_code=499, content={'detail': 'Client disconnected'}) -
85% 成功率
async for chunk in request.stream(): if await request.is_disconnected(): break
无效尝试
常见但无效的做法:
-
80% 失败
Client already disconnected; timeout doesn't help.
-
60% 失败
May cause duplicate operations if not idempotent.