Skip to content

The abort event on nodejs is deprecated #4575

Open

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.

Activity

  1. akashbirajdar04 commented on Apr 30, 2026

    @akashbirajdar04

    Hi, I’d like to work on this issue. Could you please assign it to me?

  2. damusix commented on May 19, 2026

    @damusix
    Contributor

    @akashbirajdar04 you're free to open a PR whenever. Looks like there's already a PR in order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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