-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MaxListenersExceededWarning: Possible EventTarget memory leak detected - not cleaning up AbortSignal listeners #7963
Comments
Bumping this as it's happening here for me too.
|
bumping this as it's happening for me as well. It seems like creating more than ~10 LLM calls at the same time does this. |
Hi @jscott-yps, @limcolin, and @nikhilshinday - thanks for reporting this! Is this only occurring on Also if one of you could please share an MRE that would help us to debug this more quickly. |
Unfortunately I'm unable to reproduce this without an MRE. I ran a few variations on the test below to try to trigger this warning, but was unable. I ran it with both
|
Hey @benjamincburns thanks for looking into this. It's happening only on From the logs from @jscott-yps it looks like |
It seems like there’s a potential memory leak in the consumeRunnableStream function in /langchain-core/src/runnables/base.ts. Specifically, this block: options.signal.addEventListener(
"abort",
() => {
abortController.abort();
},
{ once: true }
); 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:
In long-running apps or with multiple concurrent streams, this can become problematic. Although the listener uses { once: true }, it still accumulates if the signal is never triggered, which likely leads to a memory leak over time. I’m not 100% certain yet, but I suspect this happens because addEventListener is used without a corresponding removeEventListener, especially when calling streamEvents repeatedly in a long-lived app. Just wanted to flag this in case it’s the root cause — I’ll try confirming with a minimal reproduction soon. |
In case it helps, I am only calling streamEvents() once, not multiple times or in parallel. I've used streamEvents() (also single call) in a single-agent pattern without getting the warning. |
I'm also getting the same warning. I've attached the trace:
|
Transferred this to the LangChain JS repo, per the trace above. |
MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal]. MaxListeners is 10. Use events.setMaxListeners() to increase limit
I am not entirely sure what is causing this. There was the same issue apparently fixed in langchainjs
#6461
Did it somehow not make it's way into this?
The text was updated successfully, but these errors were encountered: