Various homeserver state FST and queue fixes #101
1 changed files with 10 additions and 5 deletions
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.
commit
01da1ae497
|
|
@ -82,11 +82,16 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
|
||||||
while (!this.queue.isEmpty()) {
|
while (!this.queue.isEmpty()) {
|
||||||
const [source, packet] = this.queue.peekFront() // same position as .shift()
|
const [source, packet] = this.queue.peekFront() // same position as .shift()
|
||||||
debugHomeserverStatus(`homeserver status: ${new Date().toISOString()} dq sourceAndPacket ${packet.t} ${packet.d?.content}`)
|
debugHomeserverStatus(`homeserver status: ${new Date().toISOString()} dq sourceAndPacket ${packet.t} ${packet.d?.content}`)
|
||||||
if (source === "Discord") {
|
try {
|
||||||
await discordPackets.dispatchPacketToBridge(passthrough.discord, packet)
|
if (source === "Discord") {
|
||||||
} else {
|
await discordPackets.dispatchPacketToBridge(passthrough.discord, packet)
|
||||||
// Unfortunately cannot await this, just have to trust it
|
} else {
|
||||||
passthrough.as.emit(`type:${packet.type}`, packet)
|
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
|
if (this.sm.currentStateName !== "recovering") return // got kicked out due to another error
|
||||||
this.queue.shift()
|
this.queue.shift()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue