-
Notifications
You must be signed in to change notification settings - Fork 385
Remove sentinel
logcontext where we log in setup
, start
and exit
#18870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ea6c587
bf21b4a
a677d9b
fce59b2
af1944b
675d94a
1bf7049
7938e8c
0a865fd
b97b2dd
301a714
c1996b6
d8f68d0
71cd3c4
0e990e6
6a98096
ea5a841
4b2e88f
1f4b391
bbe1ee7
b5ec2da
4aa0aa0
37a388c
4b61570
ae8055a
5c05a0b
b8c0857
74ab47f
e741daf
fab546d
e626f09
dcf5fca
6bbd0bf
9c74f69
e6685cc
1f95a3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Remove `sentinel` logcontext usage where we log in `setup`, `start` and exit. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ | |
from synapse.events.presence_router import load_legacy_presence_router | ||
from synapse.handlers.auth import load_legacy_password_auth_providers | ||
from synapse.http.site import SynapseSite | ||
from synapse.logging.context import PreserveLoggingContext | ||
from synapse.logging.context import LoggingContext, PreserveLoggingContext | ||
from synapse.logging.opentracing import init_tracer | ||
from synapse.metrics import install_gc_manager, register_threadpool | ||
from synapse.metrics.background_process_metrics import run_as_background_process | ||
|
@@ -183,25 +183,23 @@ def run() -> None: | |
if gc_thresholds: | ||
gc.set_threshold(*gc_thresholds) | ||
install_gc_manager() | ||
run_command() | ||
|
||
# make sure that we run the reactor with the sentinel log context, | ||
# otherwise other PreserveLoggingContext instances will get confused | ||
# and complain when they see the logcontext arbitrarily swapping | ||
# between the sentinel and `run` logcontexts. | ||
# | ||
# We also need to drop the logcontext before forking if we're daemonizing, | ||
# otherwise the cputime metrics get confused about the per-thread resource usage | ||
# appearing to go backwards. | ||
Comment on lines
-193
to
-195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was added in matrix-org/synapse#5609 and is accurately describing a real problem. But we can be way more precise about what do to here. We only need to Previously, this caused the |
||
with PreserveLoggingContext(): | ||
MadLittleMods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if daemonize: | ||
assert pid_file is not None | ||
# Reset the logging context when we start the reactor (whenever we yield control | ||
# to the reactor, the `sentinel` logging context needs to be set so we don't | ||
# leak the current logging context and erroneously apply it to the next task the | ||
# reactor event loop picks up) | ||
with PreserveLoggingContext(): | ||
run_command() | ||
|
||
if daemonize: | ||
assert pid_file is not None | ||
|
||
if print_pidfile: | ||
print(pid_file) | ||
|
||
if print_pidfile: | ||
print(pid_file) | ||
daemonize_process(pid_file, logger) | ||
|
||
daemonize_process(pid_file, logger) | ||
run() | ||
run() | ||
|
||
|
||
def quit_with_error(error_string: str) -> NoReturn: | ||
|
@@ -601,10 +599,12 @@ def run_sighup(*args: Any, **kwargs: Any) -> None: | |
hs.get_datastores().main.db_pool.start_profiling() | ||
hs.get_pusherpool().start() | ||
|
||
def log_shutdown() -> None: | ||
with LoggingContext("log_shutdown"): | ||
logger.info("Shutting down...") | ||
|
||
# Log when we start the shut down process. | ||
hs.get_reactor().addSystemEventTrigger( | ||
"before", "shutdown", logger.info, "Shutting down..." | ||
) | ||
hs.get_reactor().addSystemEventTrigger("before", "shutdown", log_shutdown) | ||
|
||
setup_sentry(hs) | ||
setup_sdnotify(hs) | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment was added in 067b00d#diff-6e21d6a61b2f6b6f2d4ce961991ba7f27e83605f927eaa4b19d2c46a975a96c1R460-R463 (matrix-org/synapse#2027)
I can't tell exactly what's it's referring to but the one spot I was seeing
Expected logging context sentinel but found main
aroundrun_as_background_process(...)
usagehas been fixed(#18870 (comment)).Reproduction:
poetry run synapse_homeserver --config-path homeserver.yaml
LoggingContext: Expected logging context main was lost
in the logs