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

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

Closed
cmawhorter opened this Issue Jan 8, 2013 · 5 comments

Comments

Projects
None yet
3 participants
@cmawhorter

cmawhorter commented Jan 8, 2013

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.

@mcavage

This comment has been minimized.

Show comment
Hide comment
@mcavage

mcavage Jan 8, 2013

Contributor

Pretty sure this is actually node that's biting you (as in your data is emitted to nowhere). Try this:

var server.createServer();
server.pre(restify.pre.pause());
...
Contributor

mcavage commented Jan 8, 2013

Pretty sure this is actually node that's biting you (as in your data is emitted to nowhere). Try this:

var server.createServer();
server.pre(restify.pre.pause());
...
@cmawhorter

This comment has been minimized.

Show comment
Hide comment
@cmawhorter

cmawhorter Jan 8, 2013

Perfect, thanks!

as in your data is emitted to nowhere

Maybe console.log a warning for this or at least a note in the docs about it under handlers? Thanks again!

cmawhorter commented Jan 8, 2013

Perfect, thanks!

as in your data is emitted to nowhere

Maybe console.log a warning for this or at least a note in the docs about it under handlers? Thanks again!

@mcavage

This comment has been minimized.

Show comment
Hide comment
@mcavage

mcavage Jan 8, 2013

Contributor

Yeah I think it's missing from the docs :\

Contributor

mcavage commented Jan 8, 2013

Yeah I think it's missing from the docs :\

@cmawhorter

This comment has been minimized.

Show comment
Hide comment
@cmawhorter

cmawhorter Jan 8, 2013

meh. thanks for your work on restify =]

cmawhorter commented Jan 8, 2013

meh. thanks for your work on restify =]

@tthew

This comment has been minimized.

Show comment
Hide comment
@tthew

tthew Jun 13, 2013

+1 for adding to the docs!

tthew commented Jun 13, 2013

+1 for adding to the docs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment