Skip to content

Fix Busboy teardown race and multi-error handling during multipart parsing#1390

Closed
mukeshdhadhariya wants to merge 1 commit intoexpressjs:mainfrom
mukeshdhadhariya:main
Closed

Fix Busboy teardown race and multi-error handling during multipart parsing#1390
mukeshdhadhariya wants to merge 1 commit intoexpressjs:mainfrom
mukeshdhadhariya:main

Conversation

@mukeshdhadhariya
Copy link
Copy Markdown

Summary

This PR addresses a teardown timing issue #1389 in make-middleware.js that affects Busboy error handling.

Two related problems are observed:

  1. Busboy may emit a late error after teardown begins.
  2. In malformed multipart flows, Busboy can emit multiple errors, causing:
    • uncaught Unexpected end of form
    • done() being called multiple times

Root Cause

Listener cleanup timing interacts with Busboy's error emission order.
Using process.nextTick alone does not fully guarantee safe handling when multiple errors are emitted.

Evidence

Failing test:

npx mocha --reporter spec --exit --check-leaks express-integration.js --grep "two errors to be emitted by busboy"

Observed failures:

  • Uncaught Error: Unexpected end of form
  • Error: done() called multiple times

Fix

This change ensures teardown and error handling remain consistent by preventing duplicate completion and ensuring late Busboy errors are safely absorbed.

@jonchurch
Copy link
Copy Markdown
Member

slop

@jonchurch jonchurch closed this Apr 6, 2026
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.

2 participants