Skip to content

Commit

Permalink
http: Fix router process crash whilst using proxy
Browse files Browse the repository at this point in the history
When the client closes the connection before the upstream,
the proxy's error handler was calling cleanup operation like
peer close and request close twice, this fix ensures the cleanup
is performed only once, improving proxy stability.

Closes: #828
  • Loading branch information
hongzhidao committed Sep 10, 2024
1 parent cff5e09 commit 5fde2ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/nxt_h1proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,11 @@ nxt_h1p_peer_body_process(nxt_task_t *task, nxt_http_peer_t *peer,
} else if (h1p->remainder > 0) {
length = nxt_buf_chain_length(out);
h1p->remainder -= length;

if (h1p->remainder == 0) {
nxt_buf_chain_add(&out, nxt_http_buf_last(peer->request));
peer->closed = 1;
}
}

peer->body = out;
Expand Down
7 changes: 4 additions & 3 deletions src/nxt_http_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ nxt_http_proxy_error(nxt_task_t *task, void *obj, void *data)
r = obj;
peer = r->peer;

nxt_http_proto[peer->protocol].peer_close(task, peer);

nxt_mp_release(r->mem_pool);
if (!peer->closed) {
nxt_http_proto[peer->protocol].peer_close(task, peer);
nxt_mp_release(r->mem_pool);
}

nxt_http_request_error(&r->task, r, peer->status);
}
Expand Down

0 comments on commit 5fde2ff

Please sign in to comment.