Only use literal strings for process names (#16315)

This commit is contained in:
Erik Johnston 2023-09-15 09:10:24 +01:00 committed by GitHub
parent 329597022e
commit edec0b93ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 14 deletions

1
changelog.d/16315.misc Normal file
View File

@ -0,0 +1 @@
Only use literal strings for background process names.

View File

@ -200,9 +200,7 @@ class _ServiceQueuer:
if service.id in self.requests_in_flight: if service.id in self.requests_in_flight:
return return
run_as_background_process( run_as_background_process("as-sender", self._send_request, service)
"as-sender-%s" % (service.id,), self._send_request, service
)
async def _send_request(self, service: ApplicationService) -> None: async def _send_request(self, service: ApplicationService) -> None:
# sanity-check: we shouldn't get here if this service already has a sender # sanity-check: we shouldn't get here if this service already has a sender
@ -478,14 +476,11 @@ class _Recoverer:
self.backoff_counter = 1 self.backoff_counter = 1
def recover(self) -> None: def recover(self) -> None:
def _retry() -> None:
run_as_background_process(
"as-recoverer-%s" % (self.service.id,), self.retry
)
delay = 2**self.backoff_counter delay = 2**self.backoff_counter
logger.info("Scheduling retries on %s in %fs", self.service.id, delay) 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: def _backoff(self) -> None:
# cap the backoff to be around 8.5min => (2^9) = 512 secs # cap the backoff to be around 8.5min => (2^9) = 512 secs

View File

@ -48,6 +48,9 @@ from synapse.metrics._types import Collector
if TYPE_CHECKING: if TYPE_CHECKING:
import resource import resource
# Old versions don't have `LiteralString`
from typing_extensions import LiteralString
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -191,7 +194,7 @@ R = TypeVar("R")
def run_as_background_process( def run_as_background_process(
desc: str, desc: "LiteralString",
func: Callable[..., Awaitable[Optional[R]]], func: Callable[..., Awaitable[Optional[R]]],
*args: Any, *args: Any,
bg_start_span: bool = True, bg_start_span: bool = True,
@ -259,7 +262,7 @@ P = ParamSpec("P")
def wrap_as_background_process( def wrap_as_background_process(
desc: str, desc: "LiteralString",
) -> Callable[ ) -> Callable[
[Callable[P, Awaitable[Optional[R]]]], [Callable[P, Awaitable[Optional[R]]]],
Callable[P, "defer.Deferred[Optional[R]]"], Callable[P, "defer.Deferred[Optional[R]]"],

View File

@ -84,9 +84,7 @@ class ExpiringCache(Generic[KT, VT]):
return return
def f() -> "defer.Deferred[None]": def f() -> "defer.Deferred[None]":
return run_as_background_process( return run_as_background_process("prune_cache", self._prune_cache)
"prune_cache_%s" % self._cache_name, self._prune_cache
)
self._clock.looping_call(f, self._expiry_ms / 2) self._clock.looping_call(f, self._expiry_ms / 2)