Skip to content

fix(engine.io): catch synchronous middleware errors - #5564

Open
Yahiro025 wants to merge 1 commit into
socketio:mainfrom
Yahiro025:fix/engine-io-middleware-throw-5263
Open

Yahiro025 wants to merge 1 commit into
socketio:mainfrom
Yahiro025:fix/engine-io-middleware-throw-5263

Conversation

@Yahiro025

@Yahiro025 Yahiro025 commented Sep 27, 2026 •

Copy link
Copy Markdown

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

Synchronous throws inside engine.use(...) / io.engine.use(...) middlewares are not caught in _applyMiddlewares. Unlike next(err), a thrown error never reaches the middleware failure path, so it is not reported as MIDDLEWARE_FAILURE / connection_error.

Fixes #5263

New behavior

_applyMiddlewares wraps each middleware call so:

  • synchronous throws become callback(err)
  • rejected promises from middleware also become callback(err)

That matches the existing next(err) failure path (HTTP 400 + connection_error with MIDDLEWARE_FAILURE).

Other information (e.g. related issues)

  • Added a regression test in packages/engine.io/test/middlewares.js mirroring the existing next(err) polling case.
  • Verified with npm test --workspace=engine.io.
  • AI assistance was used to help implement/test this fix; changes were reviewed before opening the PR.

Synchronous throws (and rejected promises) from engine.use middlewares
now reach the same callback(err) path as next(err), so they surface as
MIDDLEWARE_FAILURE / connection_error instead of being lost.

Fixes socketio#5263
@Yahiro025
Yahiro025 force-pushed the fix/engine-io-middleware-throw-5263 branch from 245c601 to 75e29b7 Compare September 27, 2026 02:42
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.

Errors thrown by middlewares do not get captured or reported

1 participant