help icon indicating copy to clipboard operation
help copied to clipboard

After 5 minutes i received an error.

Open ching2018 opened this issue 2 years ago • 3 comments

Details

503 Service Unavailable I sended a request,but i got this response.

httpServerTimeout for settings moleculer-web and requestTimeout for moleculer broker config/settings

iI've set it up, but it still fails

I thought the cause might be the nodejs's requestTimeout. https://github.com/nodejs/node/blob/main/lib/_http_server.js#L383

Node.js version

v18.3.0

Example code

https://codesandbox.io/s/competent-cray-ct7zkl?file=/index.js

Operating system

ubuntu 22.04 arm64

Scope

none

Module and version

Not applicable.

ching2018 avatar Jun 21 '22 03:06 ching2018

I would ideally debug the server. For example:

$ NODE_DEBUG=http node app.js

this would print additional debug messages for the http code flow in the app. You can follow this model to debug you backend to see where things are going wrong.

Hope this helps.

gireeshpunathil avatar Jun 25 '22 12:06 gireeshpunathil

They changed the HTTP timeout behaviour - Node v16 vs v18: v16: https://github.com/nodejs/node/blob/v16.x/lib/_http_server.js v18: https://github.com/nodejs/node/blob/v18.x/lib/_http_server.js You are going to see in v18 this code:

 const requestTimeout = options.requestTimeout;
  if (requestTimeout !== undefined) {
    validateInteger(requestTimeout, 'requestTimeout', 0);
    this.requestTimeout = requestTimeout;
  } else {
    this.requestTimeout = 300_000; // 5 minutes
  }

5 minutes hardcoded here.

To fix: option 1 is to set timeouts when setting up http server:

const server = this.setupHttpServer();
server.timeouts = 120000 //timeout in milliseconds or just add "0"
server.requestTimeout = 120000 //timeout in milisendocs

Option 2 is to set requestTimeout upon each request:

req.connection.setTimeout

Tzvetelin88 avatar Oct 09 '22 09:10 Tzvetelin88

They changed the HTTP timeout behaviour - Node v16 vs v18: v16: https://github.com/nodejs/node/blob/v16.x/lib/_http_server.js v18: https://github.com/nodejs/node/blob/v18.x/lib/_http_server.js You are going to see in v18 this code:

 const requestTimeout = options.requestTimeout;
  if (requestTimeout !== undefined) {
    validateInteger(requestTimeout, 'requestTimeout', 0);
    this.requestTimeout = requestTimeout;
  } else {
    this.requestTimeout = 300_000; // 5 minutes
  }

5 minutes hardcoded here.

To fix: option 1 is to set timeouts when setting up http server:

const server = this.setupHttpServer();
server.timeouts = 120000 //timeout in milliseconds
server.requestTimeout = 120000 //timeout in milisendocs

Option 2 is to set requestTimeout upon each request:

req.connection.setTimeout

Thank you for your reply, which helped me a lot

ching2018 avatar Oct 09 '22 09:10 ching2018

@ching2018 - is this issue resolved?

gireeshpunathil avatar Aug 02 '23 02:08 gireeshpunathil

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar May 08 '24 01:05 github-actions[bot]

It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.

github-actions[bot] avatar Jun 07 '24 01:06 github-actions[bot]

@gireeshpunathil I can confirm that the provided solution from @Tzvetelin88 is working. However, this was a breaking change, and I think that it should be mentioned somewhere.

Tomas2D avatar Jun 07 '24 08:06 Tomas2D