2

The timeout middleware : https://github.com/expressjs/timeout#api seems useful to have to timeout for hanging http requests.

However the middleware documentation mentions it's bad to use it as a top-level middleware (https://github.com/expressjs/timeout#api)

NOTE This module is not recommend as a "top-level" middleware (i.e. do not recommend for use as app.use(timeout(5000))).

Any idea why? Makes me wonder if it should be used at any level at all.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • 2
    My first guess would be that it would interfere if someone were trying to download a large static file from your site. So instead of doing `app.use(timeout(5000)))`, you should give a prefix that you want long requests to timeout on, such as: `app.use('/api', timeout(5000)))`. –  Jun 08 '14 at 13:41
  • it will stop the request flow on a timeout. but why? if we have not done anything and have not checked down the server (stream)? – diproart Jun 08 '14 at 14:34

1 Answers1

0

As pointed out by dougwilson here : https://github.com/expressjs/timeout/issues/9#event-129212094

Because of the way middleware processing works, once this module passes the request to the next middleware (which it has to do in order for you to do work), it can no longer stop the flow, so you must take care to check if the request has timedout before you continue to act on the request.

basarat
  • 261,912
  • 58
  • 460
  • 511