Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Stop the parent process flushing the logs on exit (#8012)
Browse files Browse the repository at this point in the history
This solves the problem that the first few lines are logged twice on matrix.org. Hopefully the comments explain it.
  • Loading branch information
richvdh authored Aug 5, 2020
1 parent 8b786db commit 0a86850
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/8011.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug which caused two copies of some log lines to be written when synctl was used along with a MemoryHandler logger.
1 change: 0 additions & 1 deletion changelog.d/8011.misc

This file was deleted.

1 change: 1 addition & 0 deletions changelog.d/8012.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug which caused two copies of some log lines to be written when synctl was used along with a MemoryHandler logger.
10 changes: 8 additions & 2 deletions synapse/util/daemonize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 0a86850

Please sign in to comment.