events-backend: fix event bus timeout handling

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-05-25 16:21:59 +02:00
parent 4ea914f12e
commit 32371edb4b
2 changed files with 7 additions and 0 deletions
@@ -113,6 +113,7 @@ class DatabaseEventBusListener {
signal.addEventListener('abort', () => {
this.#listeners.delete(listener);
this.#maybeTimeoutConnection();
reject(signal.reason);
});
});
}
@@ -227,6 +227,12 @@ export async function createEventBusRouter(options: {
`Received notification for subscription '${id}' for topic '${topic}'`,
{ subject: credentials.principal.subject },
);
} catch (error) {
if (error === controller.signal.reason) {
res.end();
} else {
throw error;
}
} finally {
// A small extra delay ensures a more even spread of events across
// consumers in case some consumers are faster than others