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

Stop the parent process flushing the logs on exit #8012

Merged
merged 2 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh the refactor was mostly to support this fix. have decided to merge the newsfiles.

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