Skip to content

Conversation

devonh
Copy link
Member

@devonh devonh commented Aug 15, 2025

This PR aims to allow for a clean shutdown of the SynapseHomeServer object so that it can be fully deleted and cleaned up by garbage collection without shutting down the entire python process.

Fix https://github.com/element-hq/synapse-small-hosts/issues/50

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

MadLittleMods added a commit that referenced this pull request Sep 26, 2025
Related to #18905

These fixes were split off from
#18828 where @devonh was
seeing some test failures because `timeout_deferred(...)` is being
updated to use `Clock` utilities instead of raw `reactor` methods. This
test was failing in that branch/PR until we made this new version that
handles the logcontexts properly.

While the previous version of this test does pass on `develop`, it was
using what appears completely wrong assertions, assumptions, and bad
patterns to make it happen (see diff comments below)

---

Test originally introduced in matrix-org/synapse#4407


@attr.s(slots=True)
CALL_LATER_DELAY_TRACKING_THRESHOLD_S = 30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 30s really fine?

This means in the worst case, there is a minimum of 30s of downtime when deprovisioning and provisioning a homeserver tenant in the context of Synapse Pro for Small Hosts.

Related to discussion about just tracking all calls: #18828 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let's just track them all at this point and see how it goes.

if self._next_delayed_event_call is None:
self._next_delayed_event_call = self._clock.call_later(
delay_sec,
True if delay_sec > CALL_LATER_DELAY_TRACKING_THRESHOLD_S else False,
Copy link
Contributor

@MadLittleMods MadLittleMods Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think we have the correct solution if we want this optimization ⏩

Still seems like we should track everything or at-least we don't have very good reasoning for why not. See other conversation (#18828 (comment)) about how this forces downtime in the worst case scenarios.

Args:
deferred: The Deferred to potentially timeout.
timeout: Timeout in seconds
cancel_on_shutdown: Whether this call should be tracked for cleanup during
Copy link
Contributor

@MadLittleMods MadLittleMods Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use this anywhere? Why?

Feels like it should be removed

callback: Callable,
*args: Any,
call_later_cancel_on_shutdown: Optional[bool] = None,
call_later_cancel_on_shutdown: bool = True,
Copy link
Contributor

@MadLittleMods MadLittleMods Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still use this anywhere? Why?

Feels like it should be removed

self.server_name = (
hs.hostname
) # nb must be called this for @wrap_as_background_process
self.hs = hs # nb must be called this for @wrap_as_background_process
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still an instance in synapse/handlers/device.py that needs some adjusting

self.server_name = (
hs.hostname
) # nb must be called this for @measure_func and @wrap_as_background_process

Although in this case, we need to keep part of the comment for @measure_func

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants