Avoid infinite loop on failed claim; allow concurrent thunks
This commit is contained in:
@@ -117,7 +117,7 @@ export const publishThunk = (request: ThunkRequest) => {
|
|||||||
|
|
||||||
export const thunkWorker = new Worker<Thunk>()
|
export const thunkWorker = new Worker<Thunk>()
|
||||||
|
|
||||||
thunkWorker.addGlobalHandler(async (thunk: Thunk) => {
|
thunkWorker.addGlobalHandler((thunk: Thunk) => {
|
||||||
let event = thunk.event
|
let event = thunk.event
|
||||||
|
|
||||||
// Handle abort immediately if possible
|
// Handle abort immediately if possible
|
||||||
@@ -128,6 +128,8 @@ thunkWorker.addGlobalHandler(async (thunk: Thunk) => {
|
|||||||
event = event.wrap
|
event = event.wrap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid making this function async so multiple publishes can run concurrently
|
||||||
|
Promise.resolve().then(async () => {
|
||||||
// If the event was already signed, leave it alone. Otherwise, sign it now. This is to
|
// If the event was already signed, leave it alone. Otherwise, sign it now. This is to
|
||||||
// decrease apparent latency in the UI that results from waiting for remote signers
|
// decrease apparent latency in the UI that results from waiting for remote signers
|
||||||
if (!isSignedEvent(event)) {
|
if (!isSignedEvent(event)) {
|
||||||
@@ -182,3 +184,4 @@ thunkWorker.addGlobalHandler(async (thunk: Thunk) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {Emitter, Worker, sleep} from '@welshman/lib'
|
import {Emitter, Worker, sleep} from '@welshman/lib'
|
||||||
|
import {AUTH_JOIN} from '@welshman/util'
|
||||||
import {ConnectionMeta} from './ConnectionMeta'
|
import {ConnectionMeta} from './ConnectionMeta'
|
||||||
import {ConnectionAuth, AuthStatus} from './ConnectionAuth'
|
import {ConnectionAuth, AuthStatus} from './ConnectionAuth'
|
||||||
import {Socket, isMessage, asMessage} from './Socket'
|
import {Socket, isMessage, asMessage} from './Socket'
|
||||||
@@ -43,7 +44,7 @@ export class Connection extends Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allow relay requests through
|
// Allow relay requests through
|
||||||
if (verb === 'EVENT' && extra[0].kind === 28934) {
|
if (verb === 'EVENT' && extra[0].kind === AUTH_JOIN) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ export class ConnectionAuth {
|
|||||||
const [id, ok, message] = extra
|
const [id, ok, message] = extra
|
||||||
|
|
||||||
if (id === this.request) {
|
if (id === this.request) {
|
||||||
this.challenge = undefined
|
|
||||||
this.request = undefined
|
|
||||||
this.message = message
|
this.message = message
|
||||||
this.status = ok ? Ok : Forbidden
|
this.status = ok ? Ok : Forbidden
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import {AUTH_JOIN} from '@welshman/util'
|
||||||
import type {SignedEvent, Filter} from '@welshman/util'
|
import type {SignedEvent, Filter} from '@welshman/util'
|
||||||
import type {Message} from './Socket'
|
import type {Message} from './Socket'
|
||||||
import type {Connection} from './Connection'
|
import type {Connection} from './Connection'
|
||||||
@@ -86,20 +87,16 @@ export class ConnectionMeta {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onReceiveOk([verb, eventId, ok, notice]: Message) {
|
onReceiveOk([verb, eventId, ok, notice]: Message) {
|
||||||
// Re-enqueue pending events when auth challenge is received
|
|
||||||
if (notice?.startsWith('auth-required:')) {
|
|
||||||
const pub = this.pendingPublishes.get(eventId)
|
const pub = this.pendingPublishes.get(eventId)
|
||||||
|
|
||||||
if (pub) {
|
if (!pub) return
|
||||||
|
|
||||||
|
// Re-enqueue pending events when auth challenge is received
|
||||||
|
if (notice?.startsWith('auth-required:') && pub.event.kind !== AUTH_JOIN) {
|
||||||
this.cxn.send(['EVENT', pub.event])
|
this.cxn.send(['EVENT', pub.event])
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
const publish = this.pendingPublishes.get(eventId)
|
|
||||||
|
|
||||||
if (publish) {
|
|
||||||
this.responseCount++
|
this.responseCount++
|
||||||
this.responseTimer += Date.now() - publish.sent
|
this.responseTimer += Date.now() - pub.sent
|
||||||
this.pendingPublishes.delete(eventId)
|
this.pendingPublishes.delete(eventId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user