From ac538f755fe964899d73d48278700e120890b590 Mon Sep 17 00:00:00 2001 From: Dmitry Frank Date: Tue, 16 Jan 2018 14:14:13 +0200 Subject: [PATCH] Close undrained and stuck http connections CL: - Mongoose Web Server: close undrained and stuck http connections PUBLISHED_FROM=a11656b195dbe2ef8473455a171a583e37cedb2c --- mongoose.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mongoose.c b/mongoose.c index 4b1c6297..7f7aad35 100644 --- a/mongoose.c +++ b/mongoose.c @@ -6435,6 +6435,13 @@ void mg_http_handler(struct mg_connection *nc, int ev, else if (hm->message.len > pd->rcvd) { /* Not yet received all HTTP body, deliver MG_EV_HTTP_CHUNK */ deliver_chunk(nc, hm, req_len); + if (nc->recv_mbuf_limit > 0 && nc->recv_mbuf.len >= nc->recv_mbuf_limit) { + LOG(LL_ERROR, ("%p recv buffer (%lu bytes) exceeds the limit " + "%lu bytes, and not drained, closing", + nc, (unsigned long) nc->recv_mbuf.len, + (unsigned long) nc->recv_mbuf_limit)); + nc->flags |= MG_F_CLOSE_IMMEDIATELY; + } } else { /* We did receive all HTTP body. */ int trigger_ev = nc->listener ? MG_EV_HTTP_REQUEST : MG_EV_HTTP_REPLY;