diff mbox series

[4/6] mongoose: set receive limit to 256KB

Message ID 20191208122844.11642-4-sbabic@denx.de
State Accepted
Headers show
Series [1/6] Updated mongoose to 6.16 | expand

Commit Message

Stefano Babic Dec. 8, 2019, 12:28 p.m. UTC
After 6.132, mongoose introduces with commit
93286836f944cf71c0f344eab8c1b0a29666f82a that all data are read from
socket during receive poll. This can exhaust memory and cause a
deadlock, because the transfer to IPC is much slower. Avoid to read full
data and sync the receive with IPC by setting a limit for the incoming
data to be quite the same as the size of the UDS in the IPC.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 mongoose/mongoose_interface.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index a4253b4..3296bc3 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -586,6 +586,15 @@  int start_mongoose(const char *cfgfname, int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
+	/*
+	 * The Event Handler in Webserver will read from socket until there is data.
+	 * This does not guarantes a flow control because data are forwarded
+	 * to SWUpdate internal IPC. If this is not called in blocking mode,
+	 * the Webserver should just read from socket to fill the IPC, but without
+	 * filling all memory.
+	 */
+	nc->recv_mbuf_limit = 256 * 1024;
+
 	mg_set_protocol_http_websocket(nc);
 	mg_register_http_endpoint(nc, "/restart", restart_handler);
 	mg_register_http_endpoint(nc, "/upload", MG_CB(upload_handler, NULL));