Avoid infinite loop on failed claim; allow concurrent thunks

This commit is contained in:
Jon Staab
2024-10-17 12:49:42 -07:00
parent d20d38a838
commit c121997a5f
4 changed files with 58 additions and 59 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import {Emitter, Worker, sleep} from '@welshman/lib'
import {AUTH_JOIN} from '@welshman/util'
import {ConnectionMeta} from './ConnectionMeta'
import {ConnectionAuth, AuthStatus} from './ConnectionAuth'
import {Socket, isMessage, asMessage} from './Socket'
@@ -43,7 +44,7 @@ export class Connection extends Emitter {
}
// Allow relay requests through
if (verb === 'EVENT' && extra[0].kind === 28934) {
if (verb === 'EVENT' && extra[0].kind === AUTH_JOIN) {
return false
}
-2
View File
@@ -46,8 +46,6 @@ export class ConnectionAuth {
const [id, ok, message] = extra
if (id === this.request) {
this.challenge = undefined
this.request = undefined
this.message = message
this.status = ok ? Ok : Forbidden
}
+9 -12
View File
@@ -1,3 +1,4 @@
import {AUTH_JOIN} from '@welshman/util'
import type {SignedEvent, Filter} from '@welshman/util'
import type {Message} from './Socket'
import type {Connection} from './Connection'
@@ -86,20 +87,16 @@ export class ConnectionMeta {
}
onReceiveOk([verb, eventId, ok, notice]: Message) {
const pub = this.pendingPublishes.get(eventId)
if (!pub) return
// Re-enqueue pending events when auth challenge is received
if (notice?.startsWith('auth-required:')) {
const pub = this.pendingPublishes.get(eventId)
if (pub) {
this.cxn.send(['EVENT', pub.event])
}
}
const publish = this.pendingPublishes.get(eventId)
if (publish) {
if (notice?.startsWith('auth-required:') && pub.event.kind !== AUTH_JOIN) {
this.cxn.send(['EVENT', pub.event])
} else {
this.responseCount++
this.responseTimer += Date.now() - publish.sent
this.responseTimer += Date.now() - pub.sent
this.pendingPublishes.delete(eventId)
}
}