Various homeserver state FST and queue fixes #101

Open
l1s5 wants to merge 6 commits from l1s5/out-of-your-element:homeserver-online-check-fixes into main
Showing only changes of commit e1f14ff1b9 - Show all commits

matrix: ignore stale ping results in homeserver status machinery

On the off chance that something invokes `waitForOnline` during
`checking` or `offline` (e.g. on a `GUILD_CREATE` event from discord),
the state might have changed in between we send a ping and receive it.
This commit adds guards to not act on such a stale ping result.
l1s5 2026-10-28 08:18:33 +09:00
Signed by untrusted user: l1s5
GPG key ID: D0A90CC905B58D9B

View file

@ -42,6 +42,8 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
this.checkingWhileOnline = event === "check assume online"
const pingResult = await api.ping().catch(e => ({ok: false}))
this.lastCheck = Date.now()
// ping result is stale if something else changed the state in the async gap
if (this.sm.currentStateName !== "checking") return
if (pingResult.ok && !this.queue.isEmpty()) {
this.sm.doTransition("check ok with queue")
} else if (pingResult.ok) {
@ -60,6 +62,8 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
this.pingInterval = setInterval(async () => {
const pingResult = await api.ping().catch(e => ({ok: false, status: "net", root: e.message}))
this.lastCheck = Date.now()
// ping result is stale if something else changed the state in the async gap
if (this.sm.currentStateName !== "offline") return
if (pingResult.ok) {
this.sm.doTransition("ping ok")
}