110
nginx
timeout_error
ai_generated
true
读取上游时上游超时(110:连接超时),客户端:10.0.0.1,服务器:stream.example.com
upstream timed out (110: Connection timed out) while reading upstream, client: 10.0.0.1, server: stream.example.com
ID: nginx/proxy-read-timeout-streaming
90%修复率
85%置信度
1证据数
2024-03-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| nginx/1.18.0 | active | — | — | — |
| nginx/1.20.0 | active | — | — | — |
| nginx/1.24.0 | active | — | — | — |
| nginx/1.26.0 | active | — | — | — |
根因分析
proxy_read_timeout 对流式或长轮询响应设置过短,导致 nginx 在上游完成发送数据前关闭连接。
English
proxy_read_timeout is too short for streaming or long-polling responses, causing nginx to close the connection before the upstream finishes sending data.
官方文档
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_read_timeout解决方案
-
在 location 或 server 块中将 proxy_read_timeout 增加到 300 秒(或更高):`location /stream { proxy_read_timeout 300s; ... }` -
对于流式端点,添加 send_timeout 指令以避免客户端超时:`send_timeout 300s;`
-
在上游实现 keepalive 以减少连接开销:`upstream backend { server 127.0.0.1:8080; keepalive 32; }` 和 `proxy_http_version 1.1; proxy_set_header Connection '';`
无效尝试
常见但无效的做法:
-
80% 失败
proxy_connect_timeout controls the initial handshake, not the data transfer phase; the timeout occurs during reading, not connecting.
-
40% 失败
Keepalive affects connection reuse, not the per-request timeout for reading response data.
-
60% 失败
Infinite timeout can accumulate zombie connections, eventually exhausting worker connections or memory.