mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'req-abort' into 'main'
Fix REQ abort logic See merge request soapbox-pub/ditto!712
This commit is contained in:
commit
7248aaf6c6
1 changed files with 7 additions and 2 deletions
|
|
@ -101,6 +101,10 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
|
||||||
// HACK: Due to a bug in Deno, we need to call the close handler manually.
|
// HACK: Due to a bug in Deno, we need to call the close handler manually.
|
||||||
// https://github.com/denoland/deno/issues/27924
|
// https://github.com/denoland/deno/issues/27924
|
||||||
function closeSocket(code?: number, reason?: string): void {
|
function closeSocket(code?: number, reason?: string): void {
|
||||||
|
for (const controller of controllers.values()) {
|
||||||
|
controller.abort();
|
||||||
|
}
|
||||||
|
send(['NOTICE', `closed: ${reason} (${code})`]);
|
||||||
socket.close(code, reason);
|
socket.close(code, reason);
|
||||||
handleSocketClose();
|
handleSocketClose();
|
||||||
}
|
}
|
||||||
|
|
@ -152,9 +156,10 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
controllers.get(subId)?.abort();
|
controllers.get(subId)?.abort();
|
||||||
controllers.set(subId, controller);
|
controllers.set(subId, controller);
|
||||||
|
const signal = controller.signal;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for await (const msg of relay.req(filters, { limit: 100, timeout: conf.db.timeouts.relay })) {
|
for await (const msg of relay.req(filters, { limit: 100, signal, timeout: conf.db.timeouts.relay })) {
|
||||||
if (msg[0] === 'EVENT') {
|
if (msg[0] === 'EVENT') {
|
||||||
const [, , event] = msg;
|
const [, , event] = msg;
|
||||||
send(['EVENT', subId, purifyEvent(event)]);
|
send(['EVENT', subId, purifyEvent(event)]);
|
||||||
|
|
@ -171,8 +176,8 @@ function connectStream(socket: WebSocket, ip: string | undefined, opts: ConnectS
|
||||||
} else {
|
} else {
|
||||||
send(['CLOSED', subId, 'error: something went wrong']);
|
send(['CLOSED', subId, 'error: something went wrong']);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
controllers.delete(subId);
|
controllers.delete(subId);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue