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

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

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

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

cmawhorter opened this issue Jan 8, 2013 · 5 comments

Comments

@cmawhorter
Copy link

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
Copy link
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
Copy link
Author

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
Copy link
Contributor

mcavage commented Jan 8, 2013

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

@cmawhorter
Copy link
Author

meh. thanks for your work on restify =]

@tthew
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants