hapijs / hapijs/hapi

Error: Request timeout from node http

Open
#4,445 3 comments 0 reactions 0 assignees View on GitHub
support
Dominant language
JavaScript
Stars
14.8k
Forks
1.4k
Avg merge
22d 3h
Merged PRs (30d)
1

Description

#### 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:

```js
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](https://user-images.githubusercontent.com/23722745/231551814-a79cfaa9-84ae-40b6-a7e9-552b391b0547.png)

I think issue is somewhere in https://github.com/hapijs/hapi/blob/71ffe08d5a4d7becafee93d5e2fe1879e5bab520/lib/core.js#L543

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

[Node.js 18 requestTimeout docs](https://nodejs.org/docs/latest-v18.x/api/http.html#serverrequesttimeout)

#### 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

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

And
```
Error: Bad Request
at Server. (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
```js
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.