Sitelet https://github.com/restify/node-restify/issues/287
Skip to content

handler with async next() + bodyParser hangs requests  #287

Description

@cmawhorter

Using bodyParser after a handler that calls next() async will result in the req hanging.

  var restify = require('restify'); // version 2.0.4

  var server = restify.createServer();

  function syncHandler(req, res, next) {
    next();
  }

  function asyncHandler(req, res, next) {
    process.nextTick(function() {
      next();
    });
  }

  server.use(asyncHandler);
  server.use(restify.bodyParser());

  server.post("/hello", function(req, res, next){
   console.log(req.url, req.params);
   res.send(200);
   res.end();
  });

  server.listen(8081);
  curl -is --data "hello=world" "http://localhost:8081/hello"

If you change server.use(asyncHandler) to be syncHandler or remove/move bodyParser to the first server.use, the req will succeed; otherwise it will hang forever.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions