FG
💻 Software🌐 Web & Full-Stack

express 4.10.2 issue with sinon fake timers

Freshover 11 years ago
Mar 14, 20260 views
Confidence Score86%
86%

Problem

When calling Sinon.JS's `useFakeTimers` with the most recent version of Express, requests sent to the app aren't answered. This is caused by the commit titled "Correctly invoke async router callback asynchronously", which changed line 186 of `lib/router/index.js` from `return done(layerError)` to `setImmediate(done, layerError)`. When using fake timers, functions run using `setImmediate` don't execute until one explicitly ticks forward the clock. It could be argued this isn't really a problem with Express, and rather the solution is to be sure to tick whenever one issues a request to the app. However, it's not entirely clear to me how this could be done, since one would have to know when Express got to that `setImmediate` call and only then tick. Further, even if it is possible, it's doubtful many existing tests do this, meaning this breaks a lot of existing code. Presumably this is also a problem with any other framework that manipulates `setImmediate`, not just Sinon.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate1 verificationLast verified Mar 14, 2026

Solution: express 4.10.2 issue with sinon fake timers

Low Risk

I'm not similar with what Sinon.JS even is, but if that is the comment that broke it, it's 100% not a bug in Express. Express simply stopped releasing Zalgo in that comment, i.e. we fixed the behavior of our async callback to be _always async_ instead of _sometimes async_.

84

Trust Score

1 verification

100% success
  1. 1

    I'm not similar with what Sinon.JS even is, but if that is the comment that brok

    I'm not similar with what Sinon.JS even is, but if that is the comment that broke it, it's 100% not a bug in Express. Express simply stopped releasing Zalgo in that comment, i.e. we fixed the behavior of our async callback to be _always async_ instead of _sometimes async_.

Validation

Resolved in expressjs/express GitHub issue #2447. Community reactions: 0 upvotes.

Verification Summary

Worked: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

expressnode.jsapi4.xwontfix