summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-08-05 09:35:17 +0100
committerGitHub <noreply@github.com>2020-08-05 09:35:17 +0100
commit0a86850ba37470837cbd19b33679763851c13b73 (patch)
tree49656886049260be0da00c5aae2f20dd31457476 /synapse/util
parentbug report template: move comments into comment (#8030) (diff)
downloadsynapse-0a86850ba37470837cbd19b33679763851c13b73.tar.xz
Stop the parent process flushing the logs on exit (#8012)
This solves the problem that the first few lines are logged twice on matrix.org. Hopefully the comments explain it.
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/daemonize.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/util/daemonize.py b/synapse/util/daemonize.py
index a7913fa1af..23393cf49b 100644
--- a/synapse/util/daemonize.py
+++ b/synapse/util/daemonize.py
@@ -60,8 +60,14 @@ def daemonize_process(pid_file: str, logger: logging.Logger, chdir: str = "/") -
     process_id = os.fork()
 
     if process_id != 0:
-        # parent process
-        sys.exit(0)
+        # parent process: exit.
+
+        # we use os._exit to avoid running the atexit handlers. In particular, that
+        # means we don't flush the logs. This is important because if we are using
+        # a MemoryHandler, we could have logs buffered which are now buffered in both
+        # the main and the child process, so if we let the main process flush the logs,
+        # we'll get two copies.
+        os._exit(0)
 
     # This is the child process. Continue.