Replies: 4 comments
-
I believe this has been the design of express since day one. What do you propose should happen if next() is never called? Other frameworks either require that the returned value of next() should be returned in the middleware, like |
Beta Was this translation helpful? Give feedback.
-
I totally agree — enforcing return next() would break many existing apps, and Express's flexibility is a key part of its design. That said, in large apps or teams, it's easy to forget to call next() or res.end(), which can lead to hanging requests without any obvious errors. I'm wondering if there's a way we could catch these scenarios more easily during development — maybe through optional tooling or patterns that warn when a request remains unresolved for too long. Not proposing a breaking change to core — more like: how can we help developers detect these issues early without disrupting the current ecosystem? Curious what your thoughts are on this, or if this has been discussed before? |
Beta Was this translation helpful? Give feedback.
-
IMO this isn't just isolated to this issue too, we also have the error where data is still trying to be sent once res.end() has been called. I don't see any clear way to get be able to enforce that res.end() or next() be called, other than by adding timeouts which trigger an error if they haven't been called yet. In terms of static analysis, while it may be possible to force (imo, a good solution is to create I'm not sure if this has been discussed before though, hopefully other people can chime in here. |
Beta Was this translation helpful? Give feedback.
-
That's a great point — enforcing res.end() or next() is definitely tricky, especially with dynamic patterns. I agree that timeouts are one of the few practical runtime options we have. The idea of an express/promise layer is interesting — maybe a lightweight wrapper or plugin could be a stepping stone without needing a full rewrite. Curious what others think too. |
Beta Was this translation helpful? Give feedback.
-
name: Missing
next()
in Middleware Causes Request to Get Stuckabout: Report an issue where missing
next()
in middleware causes requests to get stuck.Description
In Express, if the
next()
function is not called in a middleware, the request will get stuck because Express doesn't know how to proceed to the next middleware or route handler. This can lead to issues where requests hang indefinitely, as no response is sent to the client.Steps to Reproduce:
next()
or send a response.Example Code:
Beta Was this translation helpful? Give feedback.
All reactions