Skip to content

Server crashes if a requested aborted during sending a response.  #4294

@mshustov

Description

@mshustov

Support plan

  • is this issue currently blocking your project? (yes/no): Yes
  • is this issue affecting a production system? (yes/no): No

Context

  • node version: v14.17.6
  • module version with issue: v20.2.0
  • last module version without issue:
  • environment (e.g. node, browser, native): node + browser (via cypress)
  • used with (e.g. hapi application, another framework, standalone, ...): "@hapi/inert": "6.0.4"
  • any other relevant information:

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

I spent the whole day struggling with the flaky integration tests that were caused by unhandled promise rejection in Hapi sever when an incoming request is aborted.
The server crashes with

│ proc [kibana] TypeError: Cannot read property 'on' of null
   │ proc [kibana]     at Object.internals.chain (@hapi/hapi/lib/transmit.js:365:18)
   │ proc [kibana]     at Object.internals.transmit (@hapi/hapi/lib/transmit.js:120:30)
   │ proc [kibana]     at Object.exports.send (@hapi/hapi/lib/transmit.js:28:25)
   │ proc [kibana]     at Request._reply (@hapi/hapi/lib/request.js:459:9)

What I learned from the code inspection so far:

I guess it might happen because of a discrepancy between response and response.request.response content in transmit method https://github.com/hapijs/hapi/blob/master/lib/transmit.js#L28
I worked around the problem locally by adding the next snippet at the very top of transmit.

    if (response.request.response.isBoom) {
      await internals.fail(request, response.request.response);
      return;
    }

I don't think it's a proper fix but I don't know Hapi codebase to address the problem on my own so I'd appreciate any hints from the maintainers before I can open a PR.

Might be related to #4244 (comment) but the issue doesn't mention any problems with runtime errors.

What was the result you got?

Hapi crashes if an incoming request is aborted while the server is sending a response.

What result did you expect?

Hapi handles the abort event gracefully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug or defect

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions