Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Request timeout from node http #4445

Open
radoslavirha opened this issue Apr 12, 2023 · 3 comments
Open

Error: Request timeout from node http #4445

radoslavirha opened this issue Apr 12, 2023 · 3 comments
Labels
support Questions, discussions, and general support

Comments

@radoslavirha
Copy link
Contributor

Support plan

  • is this issue currently blocking your project? yes:
  • is this issue affecting a production system? yes:

Context

  • node version: 18
  • module version with issue: 21.2.0
  • last module version without issue: not known
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

I'm experiencing Bad Request responses when uploading large zip archives on slow internet connection (My colleagues have slower internet connection + archive size varies so I throttle requests in chrome).

Basically I just createWriteStream and pipe payload to writer in handler.

My route:

const route = {
  method: 'POST',
  path: '/import/archive',
  handler: Handler.importArchive,
  options: {
    payload: {
      allow: [ 'application/zip', 'application/x-zip-compressed' ],
      maxBytes: Bytes('15gb'),
      output: 'stream',
      parse: false
      timeout: false
    },
    timeout: {
      server: false,
      socket: false
    }
  }

But timeouts does not work and it always crashes after ~5 mins

image

I think issue is somewhere in

const listener = this.settings.listener ?? (this.settings.tls ? Https.createServer(this.settings.tls) : Http.createServer());

where listener has default requestTimeout = 300000 - it is 5mins reported by browser ^^

Node.js 18 requestTimeout docs

What was the result you got?

{
  timestamp: 1681322109764,
  tags: [ 'connection', 'client', 'error' ],
  error: Error: Request timeout
      at new NodeError (node:internal/errors:400:5)
      at onRequestTimeout (node:_http_server:780:30)
      at Server.checkConnections (node:_http_server:593:7)
      at listOnTimeout (node:internal/timers:564:17)
      at processTimers (node:internal/timers:507:7) {
    code: 'ERR_HTTP_REQUEST_TIMEOUT'
  },
  channel: 'internal'
}

from

server.events.on('log', ...)

And

Error: Bad Request
    at Server.<anonymous> (node_modules/@hapi/hapi/lib/core.js:554:40)
    at Server.emit (node:events:513:28)
    at Socket.socketOnError (node:_http_server:818:20)
    at onRequestTimeout (node:_http_server:780:17)
    at Server.checkConnections (node:_http_server:593:7)
    at listOnTimeout (node:internal/timers:564:17)
    at processTimers (node:internal/timers:507:7) {
  data: null,
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 400,
    payload: { statusCode: 400, error: 'Bad Request', message: 'Bad Request' },
    headers: { connection: 'close' }
  }
}

from

server.ext('onPreResponse', (request, h) => {
    console.log(request.response);
    return h.continue;
  })

What result did you expect?

Successfully import archives

Is it possible to solve it? I need to increase timeout only for 1-2 routes so I wondered it could be solved with options.timeout.server/socket or options.payload.timeout.

Thanks

@radoslavirha radoslavirha added the support Questions, discussions, and general support label Apr 12, 2023
@michaellasky
Copy link

Could this be possibly caused by the missing comma after the parse option?

@radoslavirha
Copy link
Contributor Author

Hi @michaellasky ^^ is just an example with missing comma. I use eslint in code and i double checked the comma is there.

@Bacto
Copy link

Bacto commented Jul 25, 2023

Hi,

I got the same issue and it seems related to #4447
Setting server.listener.requestTimeout = 0 has solved the issue in my case :)

Best,
Adrien

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants