Skip to content

fix(downloads): prevent backpressure listener leaks#217

Open
lubluniky wants to merge 1 commit into
sybil-solutions:mainfrom
lubluniky:fix/download-backpressure-listeners
Open

fix(downloads): prevent backpressure listener leaks#217
lubluniky wants to merge 1 commit into
sybil-solutions:mainfrom
lubluniky:fix/download-backpressure-listeners

Conversation

@lubluniky

Copy link
Copy Markdown
Contributor

Closes #216

Summary

  • replace the per-drain listener pair with a wait that removes both temporary listeners when either drain or error settles it
  • keep one lifecycle error tracker so a writer failure between backpressure cycles is surfaced instead of becoming unhandled or silently absorbed
  • cover repeated drain cleanup, failed waits, and between-cycle writer errors

Before this change, 12 successful drain cycles left 12 stale error listeners and emitted MaxListenersExceededWarning. The regression test now pins one lifecycle listener during the transfer and zero listeners after disposal.

Validation

cd controller && bun test src/modules/engines/downloads/stream-backpressure.test.ts tests/integration/download-manager-run.test.ts  # 7 passed
cd controller && bun run test:unit        # 145 passed
cd controller && bun run test:integration # 117 passed
cd controller && bun run typecheck
cd controller && bun run lint
cd controller && bun run check
npm run check

The pre-push frontend quality gate also passed, including the production Next.js build.

Environment note: a clean npm ci on current main hits the existing xterm beta peer-version conflict, so the root gate was run after npm ci --legacy-peer-deps; the lockfile is unchanged.

UI changes

None. This only changes the controller's model-download stream lifecycle.

Risks / rollout notes

Low. Download bytes, Range resume behavior, persistence, and progress updates are unchanged. The only behavioral difference is bounded listener lifetime and deterministic propagation of asynchronous writer failures. No migration or deployment step is required.

@lubluniky
lubluniky requested a review from 0xSero as a code owner July 13, 2026 20:41
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.

[BUG] Model download backpressure leaks writer error listeners

1 participant