jsonlogger: increase pipe buffer to reduce likelihood of corrupted messages
Our JSON messages can get rather large which can cause a buffer overrun when the reading program is not scheduled at the same time. When the kernel returns EAGAIN we abort writing the current JSON message. However, the unfinished (and thus invalid) JSON message is still in the pipe and will be processed by the reading program. Increase the pipe buffer from the default 65536 to reduce the likelihood of this happening. It's difficult to completely prevent the issue as we don't want to slow down the main program due to slow logging.
This commit is contained in:
parent
cdabe187fc
commit
26786a8569
|
@ -1,3 +1,6 @@
|
||||||
|
// For F_SETPIPE_SZ
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -29,6 +32,12 @@ static bool start_message(void)
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Increase pipe buffer to prevent/reduce EAGAIN during a JSON
|
||||||
|
// message to prevent corrupted JSON messages. 1048576 is the
|
||||||
|
// current maximum as permitted by the Linux kernel.
|
||||||
|
if (fcntl(m_fifo_fd, F_SETPIPE_SZ, 1048576) < 0) {
|
||||||
|
perror("fcntl");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ret = write(m_fifo_fd, "{", 1);
|
ssize_t ret = write(m_fifo_fd, "{", 1);
|
||||||
|
|
Loading…
Reference in a new issue