Skip to content

Conversation

@ericallam
Copy link
Member

@ericallam ericallam commented Dec 8, 2025

Note

Centralizes SIGTERM handling in DevSupervisor and removes per-run SIGTERM listeners in DevRunController to avoid MaxListenersExceededWarning under high concurrency.

  • Dev runtime:
    • SIGTERM handling: Add centralized handler in packages/cli-v3/src/dev/devSupervisor.ts to gracefully stop all run controllers; unregisters on shutdown().
    • Cleanup: Remove per-controller SIGTERM listener and handler from packages/cli-v3/src/entryPoints/dev-run-controller.ts to reduce event listeners and warnings.
  • Changeset: Add patch note in .changeset/fuzzy-ghosts-admire.md.

Written by Cursor Bugbot for commit 5ad2f53. This will update automatically on new commits. Configure here.

@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

🦋 Changeset detected

Latest commit: 5ad2f53

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
trigger.dev Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
references-realtime-hooks-test Patch
references-realtime-streams Patch
references-telemetry Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/python Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

SIGTERM handling for graceful shutdown was centralized in DevSupervisor: a SIGTERM handler is added that stops all active DevRunController instances and awaits their completion with Promise.allSettled; the handler is registered at initialization and removed on shutdown. Corresponding per-controller SIGTERM handling was removed from DevRunController (constructor registration, private sigterm method, and cleanup in stop). A changeset entry was added documenting a patch fix for "max listeners exceeded" warnings when running >10 concurrent runs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify DevSupervisor correctly discovers/tracks all active DevRunController instances before invoking stop().
  • Confirm Promise.allSettled usage preserves and surfaces errors appropriately (no silent failure masking).
  • Ensure SIGTERM handler is registered at the correct lifecycle point and reliably removed during supervisor shutdown.
  • Validate removal of per-controller SIGTERM listeners eliminates the listener-count issue without introducing other memory leaks or missed shutdown paths.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete, missing most required template sections like the issue link, checklist items, testing steps, and changelog details. Fill in the Closes #, complete the checklist, add detailed testing steps, and provide a clear changelog summary to match the template structure.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing max listeners warnings by refactoring SIGTERM handling to the DevSupervisor level when running concurrent runs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea23888 and 5ad2f53.

📒 Files selected for processing (3)
  • .changeset/fuzzy-ghosts-admire.md (1 hunks)
  • packages/cli-v3/src/dev/devSupervisor.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-controller.ts (0 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/cli-v3/src/dev/devSupervisor.ts (1)

141-143: Centralized SIGTERM handling in DevSupervisor looks correct and should fix the max listeners warnings.

Registering a single process.on("SIGTERM", this.#handleSigterm) in init() and removing it in shutdown() avoids per‑run listeners and the associated MaxListenersExceededWarning, while #handleSigterm correctly iterates all runControllers and stops them concurrently with Promise.allSettled.

Two small, non‑blocking refinements you might consider:

  • Log rejected results from Promise.allSettled so unexpected failures in controller.stop() are visible in dev logs.
  • Optionally guard against re‑entrancy (e.g., if multiple SIGTERMs arrive) with a simple flag so you don’t trigger multiple global stop sequences in parallel, though this is mostly defensive.

Overall, the lifecycle and cleanup behavior here looks sound.

Also applies to: 148-156, 159-159

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fba9e9 and ea23888.

📒 Files selected for processing (3)
  • .changeset/fuzzy-ghosts-admire.md (1 hunks)
  • packages/cli-v3/src/dev/devSupervisor.ts (1 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-controller.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/cli-v3/src/entryPoints/dev-run-controller.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

Files:

  • packages/cli-v3/src/dev/devSupervisor.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Files:

  • packages/cli-v3/src/dev/devSupervisor.ts
**/*.{js,ts,jsx,tsx,json,md,css,scss}

📄 CodeRabbit inference engine (AGENTS.md)

Format code using Prettier

Files:

  • packages/cli-v3/src/dev/devSupervisor.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 2593
File: packages/core/src/v3/workers/warmStartClient.ts:168-170
Timestamp: 2025-10-08T11:48:12.327Z
Learning: The trigger.dev runners execute only in Node 21 and 22 environments, so modern Node.js APIs like AbortSignal.any (introduced in v20.3.0) are supported.
📚 Learning: 2025-10-08T11:48:12.327Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 2593
File: packages/core/src/v3/workers/warmStartClient.ts:168-170
Timestamp: 2025-10-08T11:48:12.327Z
Learning: The trigger.dev runners execute only in Node 21 and 22 environments, so modern Node.js APIs like AbortSignal.any (introduced in v20.3.0) are supported.

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Run `npx trigger.devlatest dev` to start the Trigger.dev development server

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Control concurrency using the `queue` property with `concurrencyLimit` option

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `runs.subscribeToBatch()` to subscribe to changes for all runs in a batch

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Limit task duration using the `maxDuration` property (in seconds)

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2025-11-27T16:27:35.304Z
Learnt from: CR
Repo: triggerdotdev/trigger.dev PR: 0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-11-27T16:27:35.304Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : Use `batch.trigger()` to trigger multiple different tasks at once from backend code

Applied to files:

  • .changeset/fuzzy-ghosts-admire.md
📚 Learning: 2024-10-18T15:41:52.352Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 1418
File: packages/core/src/v3/errors.ts:364-371
Timestamp: 2024-10-18T15:41:52.352Z
Learning: In `packages/core/src/v3/errors.ts`, within the `taskRunErrorEnhancer` function, `error.message` is always defined, so it's safe to directly call `error.message.includes("SIGTERM")` without additional checks.

Applied to files:

  • packages/cli-v3/src/dev/devSupervisor.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Cursor Bugbot
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: typecheck / typecheck
🔇 Additional comments (1)
.changeset/fuzzy-ghosts-admire.md (1)

1-5: Changeset metadata and summary look consistent with the code change.

The package name, bump type, and description clearly match the intent of centralizing SIGTERM handling to avoid max listeners warnings; nothing else to change here.

@ericallam ericallam force-pushed the fix/dev-cli-max-listeners-exceeded branch from ea23888 to 5ad2f53 Compare December 9, 2025 09:53
@ericallam ericallam merged commit c021d1d into main Dec 9, 2025
28 of 29 checks passed
@ericallam ericallam deleted the fix/dev-cli-max-listeners-exceeded branch December 9, 2025 09:54
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.

4 participants