fix(core): Resolve AbortSignal MaxListenersExceededWarning (#5950) (#16735)

This commit is contained in:
Spencer
2026-01-22 20:16:00 +00:00
committed by GitHub
parent e2ddaedab4
commit 5d68d8cda5
5 changed files with 41 additions and 20 deletions
@@ -1369,9 +1369,13 @@ describe('LocalAgentExecutor', () => {
(async function* () { (async function* () {
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
// This promise resolves when aborted, ending the generator. // This promise resolves when aborted, ending the generator.
signal?.addEventListener('abort', () => { signal?.addEventListener(
resolve(); 'abort',
}); () => {
resolve();
},
{ once: true },
);
}); });
})(), })(),
); );
@@ -1681,7 +1685,9 @@ describe('LocalAgentExecutor', () => {
(async function* () { (async function* () {
// This promise never resolves, it waits for abort. // This promise never resolves, it waits for abort.
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
signal?.addEventListener('abort', () => resolve()); signal?.addEventListener('abort', () => resolve(), {
once: true,
});
}); });
})(), })(),
); );
@@ -1734,7 +1740,9 @@ describe('LocalAgentExecutor', () => {
// eslint-disable-next-line require-yield // eslint-disable-next-line require-yield
(async function* () { (async function* () {
await new Promise<void>((resolve) => await new Promise<void>((resolve) =>
signal?.addEventListener('abort', () => resolve()), signal?.addEventListener('abort', () => resolve(), {
once: true,
}),
); );
})(), })(),
); );
@@ -1745,7 +1753,9 @@ describe('LocalAgentExecutor', () => {
// eslint-disable-next-line require-yield // eslint-disable-next-line require-yield
(async function* () { (async function* () {
await new Promise<void>((resolve) => await new Promise<void>((resolve) =>
signal?.addEventListener('abort', () => resolve()), signal?.addEventListener('abort', () => resolve(), {
once: true,
}),
); );
})(), })(),
); );
@@ -346,12 +346,16 @@ describe('SessionSummaryService', () => {
10000, 10000,
); );
abortSignal?.addEventListener('abort', () => { abortSignal?.addEventListener(
clearTimeout(timeoutId); 'abort',
const abortError = new Error('This operation was aborted'); () => {
abortError.name = 'AbortError'; clearTimeout(timeoutId);
reject(abortError); const abortError = new Error('This operation was aborted');
}); abortError.name = 'AbortError';
reject(abortError);
},
{ once: true },
);
}), }),
); );
+7 -4
View File
@@ -1043,10 +1043,13 @@ describe('mcp-client', () => {
if (options?.signal?.aborted) { if (options?.signal?.aborted) {
return reject(new Error('Operation aborted')); return reject(new Error('Operation aborted'));
} }
options?.signal?.addEventListener('abort', () => { options?.signal?.addEventListener(
reject(new Error('Operation aborted')); 'abort',
}); () => {
// Intentionally do not resolve immediately to simulate lag reject(new Error('Operation aborted'));
},
{ once: true },
);
}), }),
), ),
listPrompts: vi.fn().mockResolvedValue({ prompts: [] }), listPrompts: vi.fn().mockResolvedValue({ prompts: [] }),
+1 -1
View File
@@ -242,7 +242,7 @@ export abstract class BaseToolInvocation<
} }
}; };
abortSignal.addEventListener('abort', abortHandler); abortSignal.addEventListener('abort', abortHandler, { once: true });
timeoutId = setTimeout(() => { timeoutId = setTimeout(() => {
cleanup(); cleanup();
@@ -350,9 +350,13 @@ describe('FixLLMEditWithInstruction', () => {
if (abortSignal?.aborted) { if (abortSignal?.aborted) {
return reject(new DOMException('Aborted', 'AbortError')); return reject(new DOMException('Aborted', 'AbortError'));
} }
abortSignal?.addEventListener('abort', () => { abortSignal?.addEventListener(
reject(new DOMException('Aborted', 'AbortError')); 'abort',
}); () => {
reject(new DOMException('Aborted', 'AbortError'));
},
{ once: true },
);
}), }),
); );