Skip to content

Conversation

andrewdoro
Copy link
Contributor

Fixes #7963

We are seeing this error on prod at Anara.
We are using Vercel Fluid compute to optimize serverless execution.

This results in long running processes. The addEventListener is not being cleaned up when doing multiple executions.

This error also happened a year ago. Implemented a similar fix.
#6461

adds an abort listener to the passed options.signal, but never removes it manually.

When Runnable.stream() or streamEvents() is called repeatedly with the same signal (or multiple times in parallel), the listeners accumulate, eventually triggering:

(node:75561) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal]. MaxListeners is 10. Use events.setMaxListeners() to increase limit
(Use node --trace-warnings ... to show where the warning was created)
In long-running apps or with multiple concurrent streams, this can become problematic.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 16, 2025
Copy link

vercel bot commented Jun 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Jun 16, 2025 9:32am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Jun 16, 2025 9:32am

@dosubot dosubot bot added the auto:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jun 16, 2025
@hntrl
Copy link
Member

hntrl commented Jun 16, 2025

@andrewdoro I'm fine to merge this since it's technically correct listener handling, but I'm not convinced this solves your issue. This error shouldn't be emitted because 10 or more identical event listeners were added in global space but because 10 or more were added to a single signal. Is this happening on the first streamEvents call or in subsequent calls? Are you sharing a single abort signal w/ a lot of items? (assuming this is part of a StateGraph) Do you have a lot of subgraphs?

Have you been able to test this in Vercel? If not, can you get the same error to produce when using a local node environment?

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Jun 23, 2025
@hntrl hntrl merged commit 43d4517 into langchain-ai:main Jun 23, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:bug Related to a bug, vulnerability, unexpected error with an existing feature lgtm PRs that are ready to be merged as-is size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MaxListenersExceededWarning: Possible EventTarget memory leak detected - not cleaning up AbortSignal listeners

3 participants