Various homeserver state FST and queue fixes #101
1 changed files with 4 additions and 0 deletions
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.
commit
e1f14ff1b9
|
|
@ -42,6 +42,8 @@ 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()
|
||||||
|
// 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()) {
|
if (pingResult.ok && !this.queue.isEmpty()) {
|
||||||
this.sm.doTransition("check ok with queue")
|
this.sm.doTransition("check ok with queue")
|
||||||
} else if (pingResult.ok) {
|
} else if (pingResult.ok) {
|
||||||
|
|
@ -60,6 +62,8 @@ const homeserverStatus = sync.remember(() => new class HomeserverStatus {
|
||||||
this.pingInterval = setInterval(async () => {
|
this.pingInterval = setInterval(async () => {
|
||||||
const pingResult = await api.ping().catch(e => ({ok: false, status: "net", root: e.message}))
|
const pingResult = await api.ping().catch(e => ({ok: false, status: "net", root: e.message}))
|
||||||
this.lastCheck = Date.now()
|
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) {
|
if (pingResult.ok) {
|
||||||
this.sm.doTransition("ping ok")
|
this.sm.doTransition("ping ok")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue