nginx报告upstream timed out (10060: A connection attempt failed)但实际上服务收到了请求

Posted

技术标签:

【中文标题】nginx报告upstream timed out (10060: A connection attempt failed)但实际上服务收到了请求【英文标题】:nginx report upstream timed out (10060: A connection attempt failed)but actually the service received the request 【发布时间】:2021-11-18 19:52:36 【问题描述】:

操作系统:Windows 10

服务类型:Spring Boot搭建的HTTP服务器

我的场景是提供附件上传接口,附件经过base64编码后作为body参数上传到服务。它在大多数情况下都能正常工作。今天碰到一个请求,大小大概6M左右,每次nginx都会报“upstream timed out (10060: A connection attempt failed”。吹的是nginx的errorlog。

于是我用wireshark抓包,发现两个网络包之间有1分钟的间隔,可能是这个原因,但不知道怎么解释。有没有人遇到过同样的问题?

Wireshark 图片:

nginx错误日志:

2021/09/26 14:02:59 [debug] 24844#25224: *115 http upstream dummy handler
2021/09/26 14:02:59 [debug] 24844#25224: worker cycle
2021/09/26 14:02:59 [debug] 24844#25224: select event: fd:560 wr:0
2021/09/26 14:02:59 [debug] 24844#25224: select event: fd:608 wr:0
2021/09/26 14:02:59 [debug] 24844#25224: select event: fd:616 wr:0
2021/09/26 14:02:59 [debug] 24844#25224: select timer: 57
2021/09/26 14:02:59 [debug] 24844#25224: select ready 0
2021/09/26 14:02:59 [debug] 24844#25224: timer delta: 63
2021/09/26 14:02:59 [debug] 24844#25224: *115 event timer del: 616: 548607287
2021/09/26 14:02:59 [debug] 24844#25224: *115 http upstream request: "/xxx/yyy?"
2021/09/26 14:02:59 [debug] 24844#25224: *115 http upstream process upstream
2021/09/26 14:02:59 [error] 24844#25224: *115 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /xxx/yyy HTTP/1.1", upstream: "http://127.0.0.1:9099/xxx/yyy", host: "localhost:80"
2021/09/26 14:02:59 [debug] 24844#25224: *115 http upstream exit: 00000000
2021/09/26 14:02:59 [debug] 24844#25224: *115 finalize http upstream request: 502
2021/09/26 14:02:59 [debug] 24844#25224: *115 finalize http proxy request
2021/09/26 14:02:59 [debug] 24844#25224: *115 free rr peer 1 0
2021/09/26 14:02:59 [debug] 24844#25224: *115 close http upstream connection: 616
2021/09/26 14:02:59 [debug] 24844#25224: *115 free: 02B7D598, unused: 88
2021/09/26 14:02:59 [debug] 24844#25224: *115 select del event fd:616 ev:768````

【问题讨论】:

【参考方案1】:

增加proxy_read_timeout

proxy_read_timeout 300;

【讨论】:

谢谢,它成功了。但是花了60s才回复,我还是不明白为什么这么久。 不错,可能是上游服务器花了这么长时间,你能把这个标记为答案

以上是关于nginx报告upstream timed out (10060: A connection attempt failed)但实际上服务收到了请求的主要内容,如果未能解决你的问题,请参考以下文章

Nginx Upstream timed out (110: Connection timed out)

nginx 报错 upstream timed out (110: Connection timed out)解决方案

Nginx报 upstream timed out 10060

Nginx 高并发下报错 connect() failed (110: Connection timed out) while connecting to upstream

Upstream timed out错误

如何解决“504 Gateway Time-out”错误