We implement redis container deployed via kubernetes and redirect log to container log. While trigger redis coredump via redis-cli "DEBUG SEGFAULT". We don't see trace log from the container log.

While investigating the problem. We realized the root cause is due to no fflush stdout in openDirectLogFiledes. I think we may improve it?

$ git diff
diff --git a/src/debug.c b/src/debug.c
index d5a180573..6d6cce628 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -1626,6 +1626,7 @@ int openDirectLogFiledes(void) {
 void closeDirectLogFiledes(int fd) {
     int log_to_stdout = server.logfile[0] == '\0';
     if (!log_to_stdout) close(fd);
+    else fflush(stdout);
 }

 #ifdef HAVE_BACKTRACE

Comment From: oranagra

seems right. @zh1029 do you wanna make a PR?

Comment From: oranagra

actually, on a second thought, we're using write system call (not fwrite), so it should not be buffered. maybe your problem is that the container is terminated and fsync is missing?

Comment From: yossigo

It's probably not an fsync issue if it's just a container exiting (kernel / buffer cache are unaffected). @zh1029 Did you actually test this fix? My first guess would be the container imagine is based on alpine, which doesn't have backtrace support in its libc.

Comment From: zh1029

Hi, @yossigo and @oranagra , thanks for your comments and sorry for the bother. This is in-house container to integrate redis in our product and there are in-house components integrating in the container to forward log to other container of our product. It's my mistake as I can see the stack traceback after fix our own component. So I'll close the issue.