diff options
author | Zhidao HONG <z.hong@f5.com> | 2024-09-09 23:15:29 +0800 |
---|---|---|
committer | Zhidao HONG <z.hong@f5.com> | 2024-09-10 10:12:39 +0800 |
commit | 5fde2ff79c92e2bb2ff67e4537640af7d06e73b6 (patch) | |
tree | d51f2e3653e21b151262641520f7fffa41a24133 /src | |
parent | cff5e092afec17c73a0f94d75276500fd9da8403 (diff) | |
download | unit-5fde2ff79c92e2bb2ff67e4537640af7d06e73b6.tar.gz unit-5fde2ff79c92e2bb2ff67e4537640af7d06e73b6.tar.bz2 |
http: Fix router process crash whilst using proxy
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: https://github.com/nginx/unit/issues/828
Diffstat (limited to 'src')
-rw-r--r-- | src/nxt_h1proto.c | 5 | ||||
-rw-r--r-- | src/nxt_http_proxy.c | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index 5d1ed790..48c2697b 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -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; diff --git a/src/nxt_http_proxy.c b/src/nxt_http_proxy.c index 6aa3aabb..7f6ad686 100644 --- a/src/nxt_http_proxy.c +++ b/src/nxt_http_proxy.c @@ -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); } |