express-timeout-handler icon indicating copy to clipboard operation
express-timeout-handler copied to clipboard

Seems broken

Open scottc-netflix opened this issue 6 years ago • 1 comments

This library times out the request but then still tries to return the response after the request already timed out. It's possible I'm using it wrong, but docs are very limited so it's hard to tell.

Basically I'm doing something like this:

import { Router } from 'express';
import timeout from 'express-timeout-handler';

const router = new Router();

router.use(timeout.handler({
  timeout: 60000,
  onTimeout: (req, res) => {
    res.status(503).send('Service timed out');
  }
});

router.use('/myEndpoint', timeout.set(5000), bodyParser.json(), (req, res) => {
  // make a call to another service here and return result
});

I have an unhandledReject handler that picks up this:

UNHANDLED REJECTION: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client.

scottc-netflix avatar Jan 07 '20 23:01 scottc-netflix

Hi @scottc-netflix . It's not possible to replicate this unless you show us what happens inside the /myEndpoint handler. More specifically you need to show us all methods which are accessed on the res object (for example doing res.json(...)).

Oligrand avatar Jan 29 '20 08:01 Oligrand