Skip to content

Error: Request timeout from node http #4445

Open

Description

@radoslavirha

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

Activity

  1. michaellasky commented on Apr 28, 2023

    @michaellasky

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

  2. radoslavirha commented on Apr 29, 2023

    @radoslavirha
    ContributorAuthor

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

  3. Bacto commented on Jul 25, 2023

    @Bacto

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions