某天突然收到nginx检测到上游uwsgi服务中断的报警,然后过一段时间,uwsgi又自动恢复正常,这种情况偶尔发生,已经发生过几次,我想有必要去深究一下
uwsig错误日志的关键字:
*** uWSGI listen queue of socket ":6000" (fd: 6) full !!! (1024/1024) ***
*** HARAKIRI ON WORKER 13 (pid: 21576, try: 1) ***
- HARAKIRI [core 0] 10.82.156.14 - POST /api/distrib/report/exposure/?cuid=EA3E5CBAE69AA599FDFBB4F112B08ECC&ovr=6.0.1&os_level=23&device
uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 341] during GET /api/recommend/index
- HARAKIRI !!! end of worker 2 status !!!
Respawned uWSGI worker 2 (new pid: 952)
uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 341] during GET
DAMN ! worker 17 (pid: 21591) died, killed by signal 9 :( trying respawn ...
*** uWSGI listen queue of socket ":6000" (fd: 6) full !!! (1025/1024)
broken pipe 的出现
uwsgi_response_write_body_do(): Broken pipe [core/writer.c line 341] during GET /api/recommend/index
broken pipe是send、write、writev时都有可能产生的错误,当一端在写另一端关闭了的连接的时候,就会产生broken pipe的错误。所以很显然,uwsgi在向nginx write之前,nginx已经关闭了连接,为什么?因为超时了。
nginx跟uwsgi 之间的连接有一个参数uwsgi_read_timeout默认是60秒,这个参数的意思是nginx从uwsgi读取response的超时时间,如果在这个时间内,uwsgi没有返回任何响应给nginx,那么nginx跟uwsgi的连接就会关闭。nginx此时就会报错
upstream timed out (110: Connection timed out) while reading response header from ups