Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mshustov opened this issue Oct 4, 2021 · 5 comments · Fixed by #4295
Closed

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

mshustov opened this issue Oct 4, 2021 · 5 comments · Fixed by #4295
Labels
bug Bug or defect
Milestone

Comments

@mshustov
Copy link

mshustov commented Oct 4, 2021

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.

@mshustov mshustov added the support Questions, discussions, and general support label Oct 4, 2021
@devinivy devinivy added bug Bug or defect and removed support Questions, discussions, and general support labels Oct 5, 2021
@devinivy
Copy link
Member

devinivy commented Oct 5, 2021

Thanks for the report! @kanongil I know you are looking at related areas of the codebase right now, so just wanted to put this on your radar.

@kanongil
Copy link
Contributor

kanongil commented Oct 5, 2021

Thanks, this should already be handled by my incoming patch. Just need to create a test or two for this so we don't regress.

@mshustov
Copy link
Author

mshustov commented Oct 5, 2021

@kanongil is there ETA for the patch release? Is there anything I can help you with to speed up the release?

@kanongil
Copy link
Contributor

kanongil commented Oct 5, 2021

I believe I have a fix, but still working on a creating a test that fails with the current version.

ETA for PR is sometimes today.

@kanongil
Copy link
Contributor

kanongil commented Oct 5, 2021

I managed to create a test case. I have a PR in #4295.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants