Skip to content

Commit 5fde2ff

Browse files
committed
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: #828
1 parent cff5e09 commit 5fde2ff

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/nxt_h1proto.c

+5
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,11 @@ nxt_h1p_peer_body_process(nxt_task_t *task, nxt_http_peer_t *peer,
28692869
} else if (h1p->remainder > 0) {
28702870
length = nxt_buf_chain_length(out);
28712871
h1p->remainder -= length;
2872+
2873+
if (h1p->remainder == 0) {
2874+
nxt_buf_chain_add(&out, nxt_http_buf_last(peer->request));
2875+
peer->closed = 1;
2876+
}
28722877
}
28732878

28742879
peer->body = out;

src/nxt_http_proxy.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,10 @@ nxt_http_proxy_error(nxt_task_t *task, void *obj, void *data)
381381
r = obj;
382382
peer = r->peer;
383383

384-
nxt_http_proto[peer->protocol].peer_close(task, peer);
385-
386-
nxt_mp_release(r->mem_pool);
384+
if (!peer->closed) {
385+
nxt_http_proto[peer->protocol].peer_close(task, peer);
386+
nxt_mp_release(r->mem_pool);
387+
}
387388

388389
nxt_http_request_error(&r->task, r, peer->status);
389390
}

0 commit comments

Comments
 (0)