mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Fix relay always sending a CLOSED message after the client sends CLOSE
This commit is contained in:
parent
98c967dd22
commit
8dc9ea98e2
2 changed files with 5 additions and 3 deletions
|
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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'];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue