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 01da1ae497 - Show all commits

matrix: await queued m2d packets

This ensures that all m2d packets in the queue arrives in the order they
were queued, as well as being able to catch and log any errors.
l1s5 2026-10-29 21:32:26 +09:00
Signed by untrusted user: l1s5
GPG key ID: D0A90CC905B58D9B

View file

@ -82,11 +82,16 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
while (!this.queue.isEmpty()) {
const [source, packet] = this.queue.peekFront() // same position as .shift()
debugHomeserverStatus(`homeserver status: ${new Date().toISOString()} dq sourceAndPacket ${packet.t} ${packet.d?.content}`)
if (source === "Discord") {
await discordPackets.dispatchPacketToBridge(passthrough.discord, packet)
} else {
// Unfortunately cannot await this, just have to trust it
passthrough.as.emit(`type:${packet.type}`, packet)
try {
if (source === "Discord") {
await discordPackets.dispatchPacketToBridge(passthrough.discord, packet)
} else {
await Promise.all(passthrough.as.listeners(`type:${packet.type}`).map(listener => listener(packet)))
}
} catch (e) {
// `dispatchPacketToBridge` should not throw, this is here in case of dev error.
// Skip the packet so that it can't block the queue forever.
console.error("[homeserver status] Skipping a queued event that couldn't be replayed:", e)
}
if (this.sm.currentStateName !== "recovering") return // got kicked out due to another error
this.queue.shift()