Merge branch 'fix-close' into 'main'

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

See merge request soapbox-pub/ditto!730
This commit is contained in:
Alex Gleason 2025-03-28 22:51:39 +00:00
commit 5d0505f995
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 { try {
for await (const msg of relay.req(filters, { limit: 100, signal, timeout: conf.db.timeouts.relay })) { 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') { if (msg[0] === 'EVENT') {
const [, , event] = msg; const [, , event] = msg;
send(['EVENT', subId, purifyEvent(event)]); 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']); send(['CLOSED', subId, 'error: something went wrong']);
} }
} finally { } finally {
controllers.get(subId)?.abort();
controllers.delete(subId); controllers.delete(subId);
controller.abort();
} }
} }

View file

@ -324,7 +324,7 @@ export class DittoPgStore extends NPostgres {
machina.push(['EOSE', subId]); machina.push(['EOSE', subId]);
}).catch((error) => { }).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']); machina.push(['CLOSED', subId, 'error: the relay could not respond fast enough']);
} else { } else {
machina.push(['CLOSED', subId, 'error: something went wrong']); machina.push(['CLOSED', subId, 'error: something went wrong']);
@ -361,7 +361,7 @@ export class DittoPgStore extends NPostgres {
yield msg; yield msg;
} }
} catch (e) { } 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']; yield ['CLOSED', subId, 'error: the relay could not respond fast enough'];
} else { } else {
yield ['CLOSED', subId, 'error: something went wrong']; yield ['CLOSED', subId, 'error: something went wrong'];