hapijs / hapijs/hapi

The `abort` event on nodejs is deprecated

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

Description

### Runtime

node.js

### Runtime version

24

### Module version

21.4.4

### Last module version without issue

Node 17

### Used with

hapi application

### Any other relevant information

The `Request.active()` function always returns true.

The `abort` event on NodeJS's `http.ClientRequest` has been deprecated since NodeJS v17, and `hapi/lib/request.js` is depending on that function.

[1] https://github.com/hapijs/hapi/blob/master/lib/request.js#L328
[2] https://nodejs.org/api/http.html#event-abort

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

When spamming my F5 key on my browser with a request with an intentional delay, the request never got cancelled, and `active()` always returned true.

### What was the result you got?

The requests were never cancelled.

### What result did you expect?

I wrote a small plugin to work around the issue:
```ts
export const plugin: Plugin = {
name: 'earlyCancel',
register(server) {
server.ext('onPreAuth', (request, tk) => {
request.app.disconnected = false;
request.raw.req.on('close', () => {
if (!request.raw.res.writableEnded) {
request.app.disconnected = true;
}
});
return tk.continue;
});
},
};
```
And verify that when spamming F5, I was able to get some requests to be cancelled.

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.