Skip to content

The abort event on nodejs is deprecated #4575

@Nican

Description

@Nican

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:

export const plugin: Plugin<object> = {
  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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug or defect

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions