ngx_http_discard_request_body may make keepalive connection hang in CLOSE_WAIT

ak638 nginx-forum at forum.nginx.org
Tue Jan 7 16:12:37 UTC 2020


Hi,

I wonder if it's a bug. It confused me.
recv in ngx_http_discard_request_body return 0, but ignored(suppose to close
conntection soon). So the connection will stay in keepalive timer untill
timeout, while client already closed and server stay in CLOSE_WAIT.

nginx version: nginx/1.17.6
built by gcc 4.4.6 20110731 (Red Hat 4.4.6-4) (GCC) 
built with OpenSSL 1.1.1c  28 May 2019
TLS SNI support enabled
configure arguments: --with-debug --prefix=/home/qspace/nginx --user=qspace
--group=users --with-http_ssl_module --with-http_v2_module
--with-http_gzip_static_module --with-http_stub_status_module
--with-openssl=../openssl-1.1.1c --with-pcre=../pcre-4.3 --with-stream

nginx.conf: 
keepalive_timeout  65;
keepalive_requests 2048;
limit_conn_zone $binary_remote_addr zone=connperip:10m;
limit_conn connperip 1; (make it redirect to /503.html)

request:
body not empty, i.e, content_len != 0 
e.g. curl "http://127.0.0.1" -F "file=@some_file" (close conntection after
curl exit)

ngx_http_core_generic_phase -> ngx_http_finalize_request->
ngx_http_special_response_handler -> ngx_http_discard_request_body

------------------------------------------------------------------------------------------------------------------
nginx debug log:
125812:2020/01/07 16:04:18 [debug] 12255#0: *102094 **http run request:
"/50x.html?"**
125815:2020/01/07 16:04:18 [debug] 12255#0: *102094 **http read discarded
body**
125820:2020/01/07 16:04:18 [debug] 12255#0: *102094 **recv: eof:1,
avail:-1**
125827:2020/01/07 16:04:18 [debug] 12255#0: *102094 **recv: fd:14 0 of
4096**
125831:2020/01/07 16:04:18 [debug] 12255#0: *102094 http finalize request:
-4, "/50x.html?" a:1, c:1
125834:2020/01/07 16:04:18 [debug] 12255#0: *102094 **set http keepalive
handler**
125837:2020/01/07 16:04:18 [debug] 12255#0: *102094 http close request
125841:2020/01/07 16:04:18 [debug] 12255#0: *102094 http log handler
125862:2020/01/07 16:04:18 [debug] 12255#0: *102094 run cleanup:
00000000028D3F10
125867:2020/01/07 16:04:18 [debug] 12255#0: *102094 file cleanup: fd:15
125872:2020/01/07 16:04:18 [debug] 12255#0: *102094 free: 00000000028D3190,
unused: 48
125877:2020/01/07 16:04:18 [debug] 12255#0: *102094 free: 00000000028D41A0,
unused: 2655
125881:2020/01/07 16:04:18 [debug] 12255#0: *102094 free: 0000000002883620
125883:2020/01/07 16:04:18 [debug] 12255#0: *102094 hc free:
0000000000000000
125887:2020/01/07 16:04:18 [debug] 12255#0: *102094 hc busy:
0000000000000000 0
125890:2020/01/07 16:04:18 [debug] 12255#0: *102094 reusable connection: 1
125896:2020/01/07 16:04:18 [debug] 12255#0: *102094 event timer del: 14:
8799496244
125900:2020/01/07 16:04:18 [debug] 12255#0: *102094 event timer add: 14:
65000:8799556448
**...... after 65 second (keepalive_timeout)**
3928328:2020/01/07 16:05:23 [debug] 12255#0: *102094 event timer del: 14:
8799556448
3928329:2020/01/07 16:05:23 [debug] 12255#0: *102094 http keepalive handler
3928330:2020/01/07 16:05:23 [debug] 12255#0: *102094 **close http
connection: 14**
3928331:2020/01/07 16:05:23 [debug] 12255#0: *102094 reusable connection: 0
3928332:2020/01/07 16:05:23 [debug] 12255#0: *102094 free: 0000000000000000
3928333:2020/01/07 16:05:23 [debug] 12255#0: *102094 free: 00000000028D1250,
unused: 136


Thanks!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,286665,286665#msg-286665



More information about the nginx mailing list