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

POST requests hang in node v16.8 #4298

Closed
demipixel opened this issue Oct 8, 2021 · 2 comments
Closed

POST requests hang in node v16.8 #4298

demipixel opened this issue Oct 8, 2021 · 2 comments
Labels
support Questions, discussions, and general support

Comments

@demipixel
Copy link

demipixel commented Oct 8, 2021

Support plan

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

Context

  • node version: v16.8.0
  • module version with issue: 18.1.0
  • last module version without issue: works with node v14.16.0
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): Just hapi module from npm
  • any other relevant information: Not actually my issue but one I discovered from a Stackoverflow post.

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

import * as Hapi from 'hapi';

const server = new Hapi.Server({ port: 6543, host: 'localhost' });

server.route({
  method: 'POST',
  path: '/',
  handler: function (request, reply) {
    return reply.response('Reply!');
  },
});

server.start().then(function () {
  console.log('Live');
});

What was the result you got?

POST requests hangs and never calls handler. Related to this issue which mentioned both POST and OPTIONS hang in node v16. I've discovered internals.event in request.js (https://github.com/hapijs/hapi/blob/master/lib/request.js#L701) receives a 'close' event, which then does:

request._eventContext.request = null;

which then skips the handler. Putting a return right before this line makes the request get handled correctly.

In node v14.16, an end event is received before the handler is called (where it's receiving close in node v16), and close is received after the handler has finished.

What result did you expect?

Don't hang!

@demipixel demipixel added the support Questions, discussions, and general support label Oct 8, 2021
@demipixel demipixel changed the title POST requests fail in node v16 POST requests fail in node v16.8 Oct 8, 2021
@demipixel demipixel changed the title POST requests fail in node v16.8 POST requests hang in node v16.8 Oct 8, 2021
@devinivy
Copy link
Member

devinivy commented Oct 9, 2021

I believe the issue here is that hapi v18 is not supported on node v16. In node v16 the semantics of http req/res events have changed in notable ways, addressed in hapi v20 with #4225. Your best bet will be to downgrade node to v14 or upgrade hapi to v20.

@devinivy devinivy closed this as completed Oct 9, 2021
@mbplautz
Copy link

Here I am over 8 months later just having faced this problem and I am glad to see I am not the only one. I appreciate that there is a resolution to this POST hanging issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants