Overall, I am very pleased with Express and have developed very successful API's with it. However, I decided to raise this issue, because over the last couple of months, I've run into 3 separate very hard to debug issues with different apps, which all shared the same common root causes in Express.
Basically in all of the cases it boiled down to user error, and was one of two things:
- Calling
next() twice in the same middleware due to a forgotten/omitted return.
- Ending a middleware stack prematurely with
res.end() while there was more middleware expected to run
In each case, Express did not actually trigger an error, but the resulting behaviour of the app was very flaky and it took us a long time, literally hours, to pinpoint the problems which were in fact trivial to fix.
So my question is if it's possible to have Express "guard" against these kind of cases somehow and maybe depending on your configuration/settings, have Express trigger warnings if such unexpected behaviour is registered?
I realize it's probably a valid use case to have some middleware in the middle of the stack terminate the response, so it would be hard to write rules around that, but I don't think it's ever expected that the same next handler is called twice in the same middleware.
Any thoughts on how we as developers can better guard against such issues?
Overall, I am very pleased with Express and have developed very successful API's with it. However, I decided to raise this issue, because over the last couple of months, I've run into 3 separate very hard to debug issues with different apps, which all shared the same common root causes in Express.
Basically in all of the cases it boiled down to user error, and was one of two things:
next()twice in the same middleware due to a forgotten/omittedreturn.res.end()while there was more middleware expected to runIn each case, Express did not actually trigger an error, but the resulting behaviour of the app was very flaky and it took us a long time, literally hours, to pinpoint the problems which were in fact trivial to fix.
So my question is if it's possible to have Express "guard" against these kind of cases somehow and maybe depending on your configuration/settings, have Express trigger warnings if such unexpected behaviour is registered?
I realize it's probably a valid use case to have some middleware in the middle of the stack terminate the response, so it would be hard to write rules around that, but I don't think it's ever expected that the same
nexthandler is called twice in the same middleware.Any thoughts on how we as developers can better guard against such issues?