Skip to content

POST requests hang in node v16.8 #4298

Description

@demipixel

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions