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

View File

@@ -1369,9 +1369,13 @@ describe('LocalAgentExecutor', () => {
(async function* () {
await new Promise<void>((resolve) => {
// This promise resolves when aborted, ending the generator.
signal?.addEventListener('abort', () => {
resolve();
});
signal?.addEventListener(
'abort',
() => {
resolve();
},
{ once: true },
);
});
})(),
);
@@ -1681,7 +1685,9 @@ describe('LocalAgentExecutor', () => {
(async function* () {
// This promise never resolves, it waits for abort.
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
(async function* () {
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
(async function* () {
await new Promise<void>((resolve) =>
signal?.addEventListener('abort', () => resolve()),
signal?.addEventListener('abort', () => resolve(), {
once: true,
}),
);
})(),
);

View File

@@ -346,12 +346,16 @@ describe('SessionSummaryService', () => {
10000,
);
abortSignal?.addEventListener('abort', () => {
clearTimeout(timeoutId);
const abortError = new Error('This operation was aborted');
abortError.name = 'AbortError';
reject(abortError);
});
abortSignal?.addEventListener(
'abort',
() => {
clearTimeout(timeoutId);
const abortError = new Error('This operation was aborted');
abortError.name = 'AbortError';
reject(abortError);
},
{ once: true },
);
}),
);

View File

@@ -1043,10 +1043,13 @@ describe('mcp-client', () => {
if (options?.signal?.aborted) {
return reject(new Error('Operation aborted'));
}
options?.signal?.addEventListener('abort', () => {
reject(new Error('Operation aborted'));
});
// Intentionally do not resolve immediately to simulate lag
options?.signal?.addEventListener(
'abort',
() => {
reject(new Error('Operation aborted'));
},
{ once: true },
);
}),
),
listPrompts: vi.fn().mockResolvedValue({ prompts: [] }),

View File

@@ -242,7 +242,7 @@ export abstract class BaseToolInvocation<
}
};
abortSignal.addEventListener('abort', abortHandler);
abortSignal.addEventListener('abort', abortHandler, { once: true });
timeoutId = setTimeout(() => {
cleanup();

View File

@@ -350,9 +350,13 @@ describe('FixLLMEditWithInstruction', () => {
if (abortSignal?.aborted) {
return reject(new DOMException('Aborted', 'AbortError'));
}
abortSignal?.addEventListener('abort', () => {
reject(new DOMException('Aborted', 'AbortError'));
});
abortSignal?.addEventListener(
'abort',
() => {
reject(new DOMException('Aborted', 'AbortError'));
},
{ once: true },
);
}),
);