Skip to content

What is the default timeout of a req in express? #3330

Closed

Description

@flickz

Uploading a blob on azure storage and at times the request timeout before the blob successfully uploads. How can I solve this? Thanks in adv

Activity

  1. dougwilson commented on Jun 8, 2017

    @dougwilson
    Contributor

    Hi @flickz by default, Express sits on top of the built-in Node.js HTTP server.

    You can find the documentation on the timeout in the Node.js documentation: https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_server_settimeout_msecs_callback

    The default for 6.x is 2 minutes. You can use server.setTimeout(msecs) to set a different default timeout on the server.

    I hope this helps!

  2. self-assigned this
    on Jun 8, 2017
  3. flickz commented on Jun 9, 2017

    @flickz
    Author
  4. vitoravale commented on Mar 22, 2018

    @vitoravale

    @flickz did you solve the problem?

  5. flickz commented on Mar 22, 2018

    @flickz
    Author

    @vitoravale It's almost a year I can't really remember what we did as the project didn't work out. But I think it has to do with the azure storage module I used not giving the progress status of the blob while uploading, I filed the issue there.

  6. ktrzeciaknubisa commented on May 18, 2018

    @ktrzeciaknubisa

    @flickz @vitoravale I've found two ways to make it work.

    You may set the timeout either globally for entire server:

    var server = app.listen();
    server.setTimeout(500000);

    or just for specific route:

    app.post('/xxx', function (req, res) {
       req.setTimeout(500000);
    });

    IMHO the second sounds much proper :)

  7. xerosanyam commented on Sep 23, 2019

    @xerosanyam

    is there a way to know that the server closed because of timeout?

  8. xerosanyam commented on Sep 25, 2019

    @xerosanyam

    @ktrzeciaknubisa
    for some reason, the second way is not working for me
    req.setTimeout(500000);

  9. xerosanyam commented on Sep 25, 2019

    @xerosanyam

    Figured it out, it was a typo 😓
    It should be res, instead of req

    res.setTimeout(3000, function () {
        console.log('here')
      });
    
  10. ParkerOu commented on Oct 3, 2019

    @ParkerOu

    Here's my solution:

    const apiTimeout = 10 * 1000;
    app.use((req, res, next) => {
        // Set the timeout for all HTTP requests
        req.setTimeout(apiTimeout, () => {
            let err = new Error('Request Timeout');
            err.status = 408;
            next(err);
        });
        // Set the server response timeout for all HTTP requests
        res.setTimeout(apiTimeout, () => {
            let err = new Error('Service Unavailable');
            err.status = 503;
            next(err);
        });
        next();
    });
  11. luokuning commented on Oct 16, 2019

    @luokuning

    Here's my solution:

    const apiTimeout = 10 * 1000;
    app.use((req, res, next) => {
        // Set the timeout for all HTTP requests
        req.setTimeout(apiTimeout, () => {
            let err = new Error('Request Timeout');
            err.status = 408;
            next(err);
        });
        // Set the server response timeout for all HTTP requests
        res.setTimeout(apiTimeout, () => {
            let err = new Error('Service Unavailable');
            err.status = 503;
            next(err);
        });
    });

    There should be a next() call in the end of the middleware.

  12. ParkerOu commented on Oct 16, 2019

    @ParkerOu

    Thanks! I putted next() in auth.

  13. locked as resolved and limited conversation to collaborators on Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions