Repository navigation
Closed
Description
Bug Description
When running a parent task that triggers many child tasks via batchTriggerAndWait, a MaxListenersExceededWarning appears after ~10 child tasks complete. The warning indicates SIGTERM listeners are being added to the process without cleanup.
Environment
- SDK Version: 4.1.2 (
@trigger.dev/sdk,@trigger.dev/react-hooks,@trigger.dev/build) - Node.js: v22
- OS: macOS (darwin)
- Runtime: node
Steps to Reproduce
- Create a parent task that uses
batch.triggerAndWait()to trigger multiple child tasks - Child tasks are simple (send HTTP request, update parent metadata via
metadata.parent.increment()) - Run the parent task with 10+ child tasks
- Observe warning in terminal after ~10 child tasks complete
Code Structure
// Parent task
export const parentTask = task({
id: "parent-task",
run: async (payload) => {
const batchItems = [/* 13 items */];
const batchHandle = await batch.triggerAndWait<typeof childTask>(
batchItems.map(item => ({
id: "child-task",
payload: item.payload,
options: { concurrencyKey: item.payload.instanceNumber },
}))
);
// Process results...
},
});
// Child task
export const childTask = task({
id: "child-task",
queue: { concurrencyLimit: 1 },
run: async (payload) => {
// Make HTTP request
const response = await fetch(apiEndpoint, { ... });
// Update parent metadata
metadata.parent.increment("sent", 1);
return { success: true, ... };
},
});Warning Output
(node:54268) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. MaxListeners is 10. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
Expected Behavior
No warning should appear. SIGTERM listeners should either:
- Be reused across child task runs
- Be properly removed after each child task completes
Actual Behavior
Each child task run appears to add a new SIGTERM listener without removing it, causing the warning after 10+ runs.
Notes
- Functionality is not affected - tasks complete successfully and realtime metadata updates work correctly
- The warning appears to be from SDK internals managing graceful shutdown handlers
- Child tasks don't use any external clients (no Supabase, no DB connections) - only
fetchandmetadata.parent
Workaround Attempted
Tried process.setMaxListeners(50) but this just masks the issue rather than fixing the underlying listener accumulation.
Metadata
Metadata
Assignees
Labels
No labels
Activity
IBRAHIMFONYUY commentedon Nov 25, 2025
Hey!, i will see how i can work on that
ericallam commentedon Dec 20, 2025
This has been fixed