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

Error on shutdown when prescence is enabled #11517

Closed
@DMRobertson

Description

Spotted when I was reading through sytest logs.

21082-2021-12-06 18:04:19,715 - synapse.metrics.background_process_metrics - 246 - ERROR - generic_presence.on_shutdown-0 - Background process 'generic_presence.on_shutdown' threw an exception
21083-Traceback (most recent call last):
21084-  File "/venv/lib/python3.7/site-packages/synapse/metrics/background_process_metrics.py", line 242, in run
21085-    return await func(*args, **kwargs)
21086-TypeError: object NoneType can't be used in 'await' expression

The problem is that we register a call to run_as_background_process before shutdown here. We pass it the callable self._on_shutdown. The latter is a synchronous function, but run_as_background_process expects an async function.

hs.get_reactor().addSystemEventTrigger(
"before",
"shutdown",
run_as_background_process,
"generic_presence.on_shutdown",
self._on_shutdown,
)
def _on_shutdown(self) -> None:
if self._presence_enabled:
self.hs.get_tcp_replication().send_command(
ClearUserSyncsCommand(self.instance_id)
)

The symptom was introduced in #10847 when we removed maybe_awaitable. But the underlying cause is that _on_shutdown didn't return a Deferred back when we expected it to. (Plus addSystemEventTrigger obscures the call from mypy. Probably extra confusion when this was rewritten from twisted defers to asyncs.)

Metadata

Assignees

No one assigned

    Labels

    S-TolerableMinor significance, cosmetic issues, low or no impact to users.T-DefectBugs, crashes, hangs, security vulnerabilities, or other reported issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions