Fix relay always sending a CLOSED message after the client sends CLOSE

This commit is contained in:
Alex Gleason 2025-03-28 17:50:51 -05:00
parent 98c967dd22
commit 8dc9ea98e2
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 5 additions and 3 deletions

View file

@ -165,6 +165,8 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
try {
for await (const msg of relay.req(filters, { limit: 100, signal, timeout: conf.db.timeouts.relay })) {
if (!controllers.has(subId)) break;
if (msg[0] === 'EVENT') {
const [, , event] = msg;
send(['EVENT', subId, purifyEvent(event)]);
@ -186,8 +188,8 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
send(['CLOSED', subId, 'error: something went wrong']);
}
} finally {
controllers.get(subId)?.abort();
controllers.delete(subId);
controller.abort();
}
}

View file

@ -324,7 +324,7 @@ export class DittoPgStore extends NPostgres {
machina.push(['EOSE', subId]);
}).catch((error) => {
if (error instanceof Error && error.message.includes('timeout')) {
if (error instanceof Error && (error.name === 'TimeoutError' || error.message.includes('timeout'))) {
machina.push(['CLOSED', subId, 'error: the relay could not respond fast enough']);
} else {
machina.push(['CLOSED', subId, 'error: something went wrong']);
@ -361,7 +361,7 @@ export class DittoPgStore extends NPostgres {
yield msg;
}
} catch (e) {
if (e instanceof Error && e.name === 'AbortError') {
if (e instanceof Error && (e.name === 'TimeoutError' || e.message.includes('timeout'))) {
yield ['CLOSED', subId, 'error: the relay could not respond fast enough'];
} else {
yield ['CLOSED', subId, 'error: something went wrong'];