Skip to content
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 opened this issue Dec 6, 2021 · 0 comments · Fixed by #11518
Closed

Error on shutdown when prescence is enabled #11517

DMRobertson opened this issue Dec 6, 2021 · 0 comments · Fixed by #11518
Labels
S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@DMRobertson
Copy link
Contributor

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.)

@DMRobertson DMRobertson added S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant