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

Only use literal strings for process names #16315

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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/16315.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only use literal strings for background process names.
13 changes: 4 additions & 9 deletions synapse/appservice/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ def start_background_request(self, service: ApplicationService) -> None:
if service.id in self.requests_in_flight:
return

run_as_background_process(
"as-sender-%s" % (service.id,), self._send_request, service
)
run_as_background_process("as-sender", self._send_request, service)

async def _send_request(self, service: ApplicationService) -> None:
# sanity-check: we shouldn't get here if this service already has a sender
Expand Down Expand Up @@ -478,14 +476,11 @@ def __init__(
self.backoff_counter = 1

def recover(self) -> None:
def _retry() -> None:
run_as_background_process(
"as-recoverer-%s" % (self.service.id,), self.retry
)

delay = 2**self.backoff_counter
logger.info("Scheduling retries on %s in %fs", self.service.id, delay)
self.clock.call_later(delay, _retry)
self.clock.call_later(
delay, run_as_background_process, "as-recoverer", self.retry
)

def _backoff(self) -> None:
# cap the backoff to be around 8.5min => (2^9) = 512 secs
Expand Down
6 changes: 3 additions & 3 deletions synapse/metrics/background_process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from prometheus_client import Metric
from prometheus_client.core import REGISTRY, Counter, Gauge
from typing_extensions import ParamSpec
from typing_extensions import LiteralString, ParamSpec

from twisted.internet import defer

Expand Down Expand Up @@ -191,7 +191,7 @@ def update_metrics(self) -> None:


def run_as_background_process(
desc: str,
desc: LiteralString,
func: Callable[..., Awaitable[Optional[R]]],
*args: Any,
bg_start_span: bool = True,
Expand Down Expand Up @@ -259,7 +259,7 @@ async def run() -> Optional[R]:


def wrap_as_background_process(
desc: str,
desc: LiteralString,
) -> Callable[
[Callable[P, Awaitable[Optional[R]]]],
Callable[P, "defer.Deferred[Optional[R]]"],
Expand Down
4 changes: 1 addition & 3 deletions synapse/util/caches/expiringcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def __init__(
return

def f() -> "defer.Deferred[None]":
return run_as_background_process(
"prune_cache_%s" % self._cache_name, self._prune_cache
)
return run_as_background_process("prune_cache", self._prune_cache)

self._clock.looping_call(f, self._expiry_ms / 2)

Expand Down
Loading