Skip to content

Commit

Permalink
Cancel keepalive and lingering close on EOF better (ticket #2145).
Browse files Browse the repository at this point in the history
Unlike in 75e908236701, which added the logic to ngx_http_finalize_request(),
this change moves it to a more generic routine ngx_http_finalize_connection()
to cover cases when a request is finalized with NGX_DONE.

In particular, this fixes unwanted connection transition into the keepalive
state after receiving EOF while discarding request body.  With edge-triggered
event methods that means the connection will last for extra seconds as set in
the keepalive_timeout directive.
  • Loading branch information
pluknet committed Mar 24, 2021
1 parent 11477fb commit cc73d76
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/http/ngx_http_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -2643,11 +2643,6 @@ ngx_http_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
ngx_del_timer(c->write);
}

if (c->read->eof) {
ngx_http_close_request(r, 0);
return;
}

ngx_http_finalize_connection(r);
}

Expand Down Expand Up @@ -2746,6 +2741,11 @@ ngx_http_finalize_connection(ngx_http_request_t *r)

r = r->main;

if (r->connection->read->eof) {
ngx_http_close_request(r, 0);
return;
}

if (r->reading_body) {
r->keepalive = 0;
r->lingering_close = 1;
Expand Down

0 comments on commit cc73d76

Please sign in to comment.