Possible EventTarget memory leak detected #329

Open
opened 2026-02-15 18:15:57 -05:00 by yindo · 0 comments
Owner

Originally created by @fauxbytes on GitHub (Aug 4, 2025).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangGraph.js documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangGraph.js rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package).

Example Code

/**
 * https://langchain-ai.lang.chat/langgraphjs/tutorials/workflows/#orchestrator-worker
 */
import 'dotenv/config';
import { Annotation, Send, StateGraph } from '@langchain/langgraph';
import { z } from 'zod';
import { ChatOpenAI } from '@langchain/openai';

// Schema for structured output to use in planning
const sectionSchema = z.object({
  name: z.string().describe("Name for this section of the report."),
  description: z.string().describe(
    "Brief overview of the main topics and concepts to be covered in this section."
  ),
});

const sectionsSchema = z.object({
  sections: z.array(sectionSchema).describe("Sections of the report."),
});

const llm = new ChatOpenAI();

const planner = llm.withStructuredOutput(sectionsSchema);

const StateAnnotation = Annotation.Root({
  topic: Annotation<string>,
  sections: Annotation<Array<z.infer<typeof sectionSchema>>>,
  completedSections: Annotation<string[]>({
    default: () => [],
    reducer: (a, b) => a.concat(b),
  }),
  finalReport: Annotation<string>,
});

// Worker state
const WorkerStateAnnotation = Annotation.Root({
  section: Annotation<z.infer<typeof sectionSchema>>,
  completedSections: Annotation<string[]>({
    default: () => [],
    reducer: (a, b) => a.concat(b),
  }),
});

// Nodes
async function orchestrator(state: typeof StateAnnotation.State) {
  // Generate queries
  const reportSections = await planner.invoke([
    { role: "system", content: "Generate a plan for the report." },
    { role: "user", content: `Here is the report topic: ${state.topic}` },
  ]);

  return { sections: reportSections.sections };
}

async function llmCall(state: typeof WorkerStateAnnotation.State) {
  // Generate section
  const section = await llm.invoke([
    {
      role: "system",
      content: "Write a report section following the provided name and description. Include no preamble for each section. Use markdown formatting.",
    },
    {
      role: "user",
      content: `Here is the section name: ${state.section.name} and description: ${state.section.description}`,
    },
  ]);

  // Write the updated section to completed sections
  return { completedSections: [section.content] };
}

async function synthesizer(state: typeof StateAnnotation.State) {
  // List of completed sections
  const completedSections = state.completedSections;

  // Format completed section to str to use as context for final sections
  const completedReportSections = completedSections.join("\n\n---\n\n");

  return { finalReport: completedReportSections };
}

// Conditional edge function to create llm_call workers that each write a section of the report
function assignWorkers(state: typeof StateAnnotation.State) {
  // Kick off section writing in parallel via Send() API
  return state.sections.map((section) =>
    new Send("llmCall", { section })
  );
}

// Build workflow
const orchestratorWorker = new StateGraph(StateAnnotation)
  .addNode("orchestrator", orchestrator)
  .addNode("llmCall", llmCall)
  .addNode("synthesizer", synthesizer)
  .addEdge("__start__", "orchestrator")
  .addConditionalEdges(
    "orchestrator",
    assignWorkers,
    ["llmCall"]
  )
  .addEdge("llmCall", "synthesizer")
  .addEdge("synthesizer", "__end__")
  .compile();

const main = async () => {
  const state = await orchestratorWorker.invoke({
    topic: 'Create a report on LLM scaling laws'
  });
  console.log(state.finalReport);
};

main().catch(console.error);

Error Message and Stack Trace (if applicable)

(node:28308) 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)

Description

Similar to this issue, getting an error when attempting to execute this sample

System Info

$ cat package.json |jq '{dependencies, devDependencies}'
{
  "dependencies": {
    "@langchain/anthropic": "^0.3.25",
    "@langchain/core": "^0.3.66",
    "@langchain/langgraph": "^0.3.12",
    "@langchain/openai": "^0.6.3",
    "@langchain/tavily": "^0.1.4",
    "dotenv": "^17.2.0",
    "langchain": "^0.3.30",
    "sqlite": "^5.1.1",
    "typeorm": "^0.3.25",
    "zod": "^4.0.5"
  },
  "devDependencies": {
    "@types/node": "^24.0.14",
    "ts-node": "^10.9.2",
    "typescript": "^5.8.3"
  }
}
$ pnpm -v
10.11.0
$ wmic os get caption
Caption
Microsoft Windows 11 Pro
Originally created by @fauxbytes on GitHub (Aug 4, 2025). ### Checked other resources - [x] I added a very descriptive title to this issue. - [x] I searched the LangGraph.js documentation with the integrated search. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangGraph.js rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangGraph (or the specific integration package). ### Example Code ```typescript /** * https://langchain-ai.lang.chat/langgraphjs/tutorials/workflows/#orchestrator-worker */ import 'dotenv/config'; import { Annotation, Send, StateGraph } from '@langchain/langgraph'; import { z } from 'zod'; import { ChatOpenAI } from '@langchain/openai'; // Schema for structured output to use in planning const sectionSchema = z.object({ name: z.string().describe("Name for this section of the report."), description: z.string().describe( "Brief overview of the main topics and concepts to be covered in this section." ), }); const sectionsSchema = z.object({ sections: z.array(sectionSchema).describe("Sections of the report."), }); const llm = new ChatOpenAI(); const planner = llm.withStructuredOutput(sectionsSchema); const StateAnnotation = Annotation.Root({ topic: Annotation<string>, sections: Annotation<Array<z.infer<typeof sectionSchema>>>, completedSections: Annotation<string[]>({ default: () => [], reducer: (a, b) => a.concat(b), }), finalReport: Annotation<string>, }); // Worker state const WorkerStateAnnotation = Annotation.Root({ section: Annotation<z.infer<typeof sectionSchema>>, completedSections: Annotation<string[]>({ default: () => [], reducer: (a, b) => a.concat(b), }), }); // Nodes async function orchestrator(state: typeof StateAnnotation.State) { // Generate queries const reportSections = await planner.invoke([ { role: "system", content: "Generate a plan for the report." }, { role: "user", content: `Here is the report topic: ${state.topic}` }, ]); return { sections: reportSections.sections }; } async function llmCall(state: typeof WorkerStateAnnotation.State) { // Generate section const section = await llm.invoke([ { role: "system", content: "Write a report section following the provided name and description. Include no preamble for each section. Use markdown formatting.", }, { role: "user", content: `Here is the section name: ${state.section.name} and description: ${state.section.description}`, }, ]); // Write the updated section to completed sections return { completedSections: [section.content] }; } async function synthesizer(state: typeof StateAnnotation.State) { // List of completed sections const completedSections = state.completedSections; // Format completed section to str to use as context for final sections const completedReportSections = completedSections.join("\n\n---\n\n"); return { finalReport: completedReportSections }; } // Conditional edge function to create llm_call workers that each write a section of the report function assignWorkers(state: typeof StateAnnotation.State) { // Kick off section writing in parallel via Send() API return state.sections.map((section) => new Send("llmCall", { section }) ); } // Build workflow const orchestratorWorker = new StateGraph(StateAnnotation) .addNode("orchestrator", orchestrator) .addNode("llmCall", llmCall) .addNode("synthesizer", synthesizer) .addEdge("__start__", "orchestrator") .addConditionalEdges( "orchestrator", assignWorkers, ["llmCall"] ) .addEdge("llmCall", "synthesizer") .addEdge("synthesizer", "__end__") .compile(); const main = async () => { const state = await orchestratorWorker.invoke({ topic: 'Create a report on LLM scaling laws' }); console.log(state.finalReport); }; main().catch(console.error); ``` ### Error Message and Stack Trace (if applicable) (node:28308) 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) ### Description Similar to [this issue](https://github.com/langchain-ai/langgraphjs/issues/1420), getting an error when attempting to execute [this sample](https://langchain-ai.lang.chat/langgraphjs/tutorials/workflows/#orchestrator-worker) ### System Info ```bash $ cat package.json |jq '{dependencies, devDependencies}' { "dependencies": { "@langchain/anthropic": "^0.3.25", "@langchain/core": "^0.3.66", "@langchain/langgraph": "^0.3.12", "@langchain/openai": "^0.6.3", "@langchain/tavily": "^0.1.4", "dotenv": "^17.2.0", "langchain": "^0.3.30", "sqlite": "^5.1.1", "typeorm": "^0.3.25", "zod": "^4.0.5" }, "devDependencies": { "@types/node": "^24.0.14", "ts-node": "^10.9.2", "typescript": "^5.8.3" } } $ pnpm -v 10.11.0 $ wmic os get caption Caption Microsoft Windows 11 Pro ```
yindo added the bug label 2026-02-15 18:15:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#329