req is not readable after middleware used

Problem

I'm attempting to secure an API endpoint of mine with passport running on node.js version 0.8.2. The controller function I have looks something like this:

exports.create = function(req, res) {
    console.log('Request readable? ' + req.readable);

    ... stream blob in req to create blob ...
};

This works great when there is no middleware to authenticate the incoming request and "Request readable? true" is printed to the console.

When I introduce the middleware to authenticate the incoming request, the req is not readable any longer in my controller.

What am I doing wrong?

Problem courtesy of: outside2344

Solution

What was happening in this case is that I was making a call to fetch the accessToken from the database asynchronously and in this gap the stream when unreadable:

// req.readable == true here

auth(req, res, function(err) {
    // req.readable == false here

What you need to do in this situation is pause and resume the request stream:

// req.readable == true here

req.pause();
auth(req, res, function(err) {
    req.resume();
    // req.readable == true here
Solution courtesy of: outside2344

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.