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 a723c1c1a6 - Show all commits

matrix: queue d2m events while checking the homeserver

During a "check assume offline" at startup, `isRealTime()` is false,
so incoming Discord events get queued, but `queuePacket()` asserted that we
were offline or recovering. The updated assertion implicitly adds `checking`
to the list of valid states, allowing packets to be queued in this state.
l1s5 2026-10-27 16:46:22 +09:00
Signed by untrusted user: l1s5
GPG key ID: D0A90CC905B58D9B

View file

@ -42,7 +42,9 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
this.checkingWhileOnline = event === "check assume online" this.checkingWhileOnline = event === "check assume online"
const pingResult = await api.ping().catch(e => ({ok: false})) const pingResult = await api.ping().catch(e => ({ok: false}))
this.lastCheck = Date.now() this.lastCheck = Date.now()
if (pingResult.ok) { if (pingResult.ok && !this.queue.isEmpty()) {
this.sm.doTransition("check ok with queue")
} else if (pingResult.ok) {
this.sm.doTransition("check ok") this.sm.doTransition("check ok")
} else { } else {
this.sm.doTransition("check fail") this.sm.doTransition("check fail")
@ -99,6 +101,7 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
.defineTransition("online", "check assume online", "checking") .defineTransition("online", "check assume online", "checking")
.defineTransition("online", "check assume offline", "checking") .defineTransition("online", "check assume offline", "checking")
.defineTransition("checking", "check ok", "online") .defineTransition("checking", "check ok", "online")
.defineTransition("checking", "check ok with queue", "recovering")
.defineTransition("checking", "check fail", "offline") .defineTransition("checking", "check fail", "offline")
this.sm.on("enter", st => debugHomeserverStatus(`homeserver status: ${st}`)) this.sm.on("enter", st => debugHomeserverStatus(`homeserver status: ${st}`))
@ -137,10 +140,10 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
} }
/** /**
* When offline or recovering, call this for incoming packets to queue them to be sent in order later. * When not real time, call this for incoming packets to queue them to be sent in order later.
*/ */
queuePacket(sourceAndPacket) { queuePacket(sourceAndPacket) {
assert(["offline", "recovering"].includes(this.sm.currentStateName)) assert(!this.isRealTime())
this.queue.push(sourceAndPacket) this.queue.push(sourceAndPacket)
} }