Skip to content

fix: MaxListenersExceededWarning for parallel tasks (shared AbortSignal) - #2573

Open
Arpan Das (adasarpan404) wants to merge 2 commits into
langchain-ai:mainfrom
adasarpan404:fix/event-target-memory-leak
Open

fix: MaxListenersExceededWarning for parallel tasks (shared AbortSignal)#2573
Arpan Das (adasarpan404) wants to merge 2 commits into
langchain-ai:mainfrom
adasarpan404:fix/event-target-memory-leak

Conversation

@adasarpan404

Copy link
Copy Markdown

Affected issues:

Root Cause

In PregelRunner, all tasks scheduled in the same superstep (parallel execution tick) receive the exact same composedAbortSignal via config.signal.

Each LLM invocation (e.g. ChatOpenAI.invoke()) and HTTP client adds an abort listener to this shared signal. When fan-out exceeds Node.js default limit of 10 listeners, the warning is emitted.

This is not a real memory leak — it's Node.js protecting against potential leaks — but it creates noise in production and tutorial runs.

Solution

Fork the parent AbortSignal for each parallel task so every task gets its own clean AbortSignal instance while still fully propagating cancellation from the parent.

Changes

  • Updated signal handling in task scheduling to use per-task child signals via AbortSignal.any() (modern & clean).
  • Added fallback for older environments.
  • Ensured cancellation semantics remain identical.
  • Added test case for high fan-out (>10 parallel tasks) to prevent regression.

Testing

  • Verified no MaxListenersExceededWarning with 15+ parallel LLM calls.
  • Confirmed graceful abortion still works across all tasks.
  • Existing single-task and low-parallelism behavior unchanged.

Ready for review! 🚀

@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b65d4cd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@adasarpan404 Arpan Das (adasarpan404) changed the title Fix MaxListenersExceededWarning for parallel tasks (shared AbortSignal) fix MaxListenersExceededWarning for parallel tasks (shared AbortSignal) Jun 27, 2026
@adasarpan404 Arpan Das (adasarpan404) changed the title fix MaxListenersExceededWarning for parallel tasks (shared AbortSignal) fix: MaxListenersExceededWarning for parallel tasks (shared AbortSignal) Jun 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@langchain/langgraph-checkpoint

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint@2573

@langchain/langgraph-checkpoint-mongodb

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-mongodb@2573

@langchain/langgraph-checkpoint-postgres

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-postgres@2573

@langchain/langgraph-checkpoint-redis

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-redis@2573

@langchain/langgraph-checkpoint-sqlite

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-sqlite@2573

@langchain/langgraph-checkpoint-validation

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-checkpoint-validation@2573

create-langgraph

npm i https://pkg.pr.new/langchain-ai/langgraphjs/create-langgraph@2573

@langchain/langgraph-api

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-api@2573

@langchain/langgraph-cli

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-cli@2573

@langchain/langgraph

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph@2573

@langchain/langgraph-cua

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-cua@2573

@langchain/langgraph-supervisor

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-supervisor@2573

@langchain/langgraph-swarm

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-swarm@2573

@langchain/langgraph-ui

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-ui@2573

@langchain/langgraph-sdk

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/langgraph-sdk@2573

@langchain/angular

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/angular@2573

@langchain/react

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/react@2573

@langchain/svelte

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/svelte@2573

@langchain/vue

npm i https://pkg.pr.new/langchain-ai/langgraphjs/@langchain/vue@2573

commit: b65d4cd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant