diff mbox series

logd: Limit ustream write max buffer with the limit of 4096

Message ID 20210727082130.26322-1-gokulmrt@gmail.com
State Needs Review / ACK
Headers show
Series logd: Limit ustream write max buffer with the limit of 4096 | expand

Commit Message

Gokulnathan Matta Raja July 27, 2021, 8:21 a.m. UTC
If the "logread" process is blocked in write call or stopped by
pressing "CTRL+Z", the logd starts to buffer all the messages in
the write buffer. Since currently there is no limit in ustream
w.max_buffers, the logd consumes all the system memory and at a
point of time which triggers Out Of Memory.
The ustream write max_buffer of logd is limited with value 4096.

Similar ticket has been reported in,
https://github.com/openwrt/packages/issues/5604

Signed-off-by: Gokulnathan Matta Raja <gokulmrt@gmail.com>
---
 log/logd.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/log/logd.c b/log/logd.c
index 5d6c458..6ca4a2b 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -130,6 +130,8 @@  read_log(struct ubus_context *ctx, struct ubus_object *obj,
 		cl->s.stream.notify_state = client_notify_state;
 		cl->fd = fds[1];
 		ustream_fd_init(&cl->s, cl->fd);
+		/* Limit the ustream write max_buffers to avoid infinite memory consumption when no logread happens */
+		cl->s.stream.w.max_buffers = 4096;
 		list_add(&cl->list, &clients);
 		while ((!tb[READ_LINES] || count) && l) {
 			blob_buf_init(&b, 0);