diff --git a/packages/backend-common/src/context/RootContext.ts b/packages/backend-common/src/context/RootContext.ts index aa2213ccab..fd3690a945 100644 --- a/packages/backend-common/src/context/RootContext.ts +++ b/packages/backend-common/src/context/RootContext.ts @@ -18,34 +18,32 @@ import { Context } from './types'; /** * Since the root context can never abort, and since nobody is ever meant to - * dispatch events through it, we can use a static fake instance for - * efficiency. + * dispatch events through it, we can use a static fake instance for efficiency. + * + * The reason that this was initially made for the root context is that due to + * the way that we always chain contexts off of it, sometimes a huge number of + * listeners want to add themselves to something that effectively never can be + * aborted in the first place. This triggered warnings that the max listeners + * limit was exceeded. */ -const fakeAbortController = new AbortController(); -const fakeAbortSignal: AbortSignal = Object.freeze( - Object.assign( - { - aborted: false, - reason: undefined, - throwIfAborted() {}, - onabort() {}, - addEventListener() {}, - removeEventListener() {}, - dispatchEvent() { - return true; - }, - }, - fakeAbortController.signal, - ), -); +class FakeAbortSignal implements AbortSignal { + readonly aborted = false; + readonly reason = undefined; + onabort() {} + throwIfAborted() {} + addEventListener() {} + removeEventListener() {} + dispatchEvent() { + return true; + } +} /** * An empty root context. */ export class RootContext implements Context { - readonly abortSignal = fakeAbortSignal; + readonly abortSignal = new FakeAbortSignal(); readonly deadline = undefined; - value(_key: string): T | undefined { return undefined; } diff --git a/packages/backend-tasks/src/tasks/util.test.ts b/packages/backend-tasks/src/tasks/util.test.ts index e17cf1ef1f..e2536abb88 100644 --- a/packages/backend-tasks/src/tasks/util.test.ts +++ b/packages/backend-tasks/src/tasks/util.test.ts @@ -20,7 +20,7 @@ import { delegateAbortController, nowPlus, sleep, validateId } from './util'; class KnexBuilder { public build(client: string): Knex { - return knexFactory({ client }); + return knexFactory({ client, useNullAsDefault: true }); } }