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

Commit 69da4ca

Browse files
author
David Robertson
committed
Reload cache config on sighup
1 parent 2a5ce2f commit 69da4ca

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

synapse/app/_base.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
from synapse.api.constants import MAX_PDU_SIZE
5252
from synapse.app import check_bind_error
5353
from synapse.app.phone_stats_home import start_phone_stats_home
54+
from synapse.config import ConfigError
55+
from synapse.config._base import format_config_error
5456
from synapse.config.homeserver import HomeServerConfig
5557
from synapse.config.server import ManholeConfig
5658
from synapse.crypto import context_factory
@@ -426,6 +428,7 @@ def run_sighup(*args: Any, **kwargs: Any) -> None:
426428
signal.signal(signal.SIGHUP, run_sighup)
427429

428430
register_sighup(refresh_certificate, hs)
431+
register_sighup(reload_cache_config, hs.config)
429432

430433
# Load the certificate from disk.
431434
refresh_certificate(hs)
@@ -480,6 +483,22 @@ def run_sighup(*args: Any, **kwargs: Any) -> None:
480483
atexit.register(gc.freeze)
481484

482485

486+
def reload_cache_config(config: HomeServerConfig) -> None:
487+
# For mypy's benefit. It can't know that we haven't altered `config` by the time
488+
# we call this closure.
489+
assert config is not None
490+
try:
491+
# This will call CacheConfig.read_config, which will automatically call
492+
# CacheConfig.resize_all_caches.
493+
config.reload_config_section("caches")
494+
except ConfigError as e:
495+
logger.warning("Failed to reload cache config")
496+
for f in format_config_error(e):
497+
logger.warning(f)
498+
else:
499+
logger.debug("New cache config: %s", config.caches.__dict__)
500+
501+
483502
def setup_sentry(hs: "HomeServer") -> None:
484503
"""Enable sentry integration, if enabled in configuration"""
485504

0 commit comments

Comments
 (0)