Fix context propagation broken by async@2.x
Rework the REST middleware to use a hand-written version of
"async.eachSeries". Before this change, we were loosing CLS context
when the application was relying on the REST middleware to load the
context middleware.
This is fixing a problem introduced by post-1.0 versions of async,
which we upgraded to via fea3b781a
.
This commit is contained in:
parent
43a1f537db
commit
228bc7519b
|
@ -73,8 +73,21 @@ function rest() {
|
|||
if (handlers.length === 1) {
|
||||
return handlers[0](req, res, next);
|
||||
}
|
||||
async.eachSeries(handlers, function(handler, done) {
|
||||
handler(req, res, done);
|
||||
}, next);
|
||||
|
||||
executeHandlers(handlers, req, res, next);
|
||||
};
|
||||
}
|
||||
|
||||
// A trimmed-down version of async.series that preserves current CLS context
|
||||
function executeHandlers(handlers, req, res, cb) {
|
||||
var ix = -1;
|
||||
next();
|
||||
|
||||
function next(err) {
|
||||
if (err || ++ix >= handlers.length) {
|
||||
cb(err);
|
||||
} else {
|
||||
handlers[ix](req, res, next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue