Skip to content

Commit 95be8dc

Browse files
committed
Add logcontext for SIGHUP callbacks to run in
See #19095 (comment)
1 parent 44994ec commit 95be8dc

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

synapse/app/_base.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112

113113

114114
def register_sighup(
115-
homeserver_instance_id: str,
115+
hs: "HomeServer",
116116
func: Callable[P, None],
117117
*args: P.args,
118118
**kwargs: P.kwargs,
@@ -127,19 +127,25 @@ def register_sighup(
127127
*args, **kwargs: args and kwargs to be passed to the target function.
128128
"""
129129

130-
_instance_id_to_sighup_callbacks_map.setdefault(homeserver_instance_id, []).append(
131-
(func, args, kwargs)
130+
# Wrap the function so we can run it within a logcontext
131+
def _callback_wrapper(*args: P.args, **kwargs: P.kwargs) -> None:
132+
with LoggingContext(name="sighup", server_name=hs.hostname):
133+
func(*args, **kwargs)
134+
135+
_instance_id_to_sighup_callbacks_map.setdefault(hs.get_instance_id(), []).append(
136+
(_callback_wrapper, args, kwargs)
132137
)
133138

134139

135-
def unregister_sighups(instance_id: str) -> None:
140+
def unregister_sighups(homeserver_instance_id: str) -> None:
136141
"""
137142
Unregister all sighup functions associated with this Synapse instance.
138143
139144
Args:
140-
instance_id: Unique ID for this Synapse process instance.
145+
homeserver_instance_id: The unique ID for this Synapse process instance to
146+
unregister hooks for (`hs.get_instance_id()`).
141147
"""
142-
_instance_id_to_sighup_callbacks_map.pop(instance_id, [])
148+
_instance_id_to_sighup_callbacks_map.pop(homeserver_instance_id, [])
143149

144150

145151
def start_worker_reactor(
@@ -639,8 +645,8 @@ async def start(hs: "HomeServer", freeze: bool = True) -> None:
639645
)
640646

641647
setup_sighup_handling()
642-
register_sighup(hs.get_instance_id(), refresh_certificate, hs)
643-
register_sighup(hs.get_instance_id(), reload_cache_config, hs.config)
648+
register_sighup(hs, refresh_certificate, hs)
649+
register_sighup(hs, reload_cache_config, hs.config)
644650

645651
# Apply the cache config.
646652
hs.config.caches.resize_all_caches()

synapse/config/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def setup_logging(
375375
if log_config_path:
376376
server_name = hs.hostname
377377
appbase.register_sighup(
378-
hs.get_instance_id(), _reload_logging_config, server_name, log_config_path
378+
hs, _reload_logging_config, server_name, log_config_path
379379
)
380380

381381
# Log immediately so we can grep backwards.

0 commit comments

Comments
 (0)