hapijs / hapi

The Simple, Secure Framework Developers Trust

Home Page:https://hapi.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Request timeout from node http

radoslavirha opened this issue · comments

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

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

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

commented

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