hapijs / hapijs/hapi

Node sockets timeout after 2 minutes by default

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

Description

#### Context

* *node version*: node14/18
* *module version*: hapi16/20

#### What are you trying to achieve or the steps to reproduce ?
This server uses the default implementation of `route.options.timeout.socket` which states node sockets will timeout after 2 minutes. However, the route handler has a 3 minute timeout, but the socket never hangs up after 2 minutes as expected.

```js
'use strict';

const Hapi = require('@hapi/hapi');

const init = async () => {

const server = Hapi.server({
port: 4545,
host: 'localhost'
});

/**
* expecting default behavior that node socket hangs up after 2 minutes
* however this timer exceeds 2 minutes then response is returned to user
*/
server.route({
method: 'GET',
path: '/default-socket-timeout',
handler: async (request, h) => {
const timeout = delay => new Promise(resolve => setTimeout(resolve, delay));
await timeout(180 * 1000);
return 'timer is done';
}
});

await server.start();
console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {
console.log(err);
process.exit(1);
});

init();
```

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.