Fix hanging on large stack of sync routes

fixes #4899
This commit is contained in:
Douglas Christopher Wilson 2022-04-29 13:34:47 -04:00
parent 75e0c7a2c9
commit 631ada0c64
3 changed files with 28 additions and 9 deletions

View File

@ -1,3 +1,8 @@
unreleased
==========
* Fix hanging on large stack of sync routes
4.18.0 / 2022-04-25
===================

View File

@ -279,14 +279,14 @@ proto.handle = function handle(req, res, out) {
// this should be done for the layer
self.process_params(layer, paramcalled, req, res, function (err) {
if (err) {
return next(layerError || err);
next(layerError || err)
} else if (route) {
layer.handle_request(req, res, next)
} else {
trim_prefix(layer, layerError, layerPath, path)
}
if (route) {
return layer.handle_request(req, res, next);
}
trim_prefix(layer, layerError, layerPath, path);
sync = 0
});
}
@ -327,8 +327,6 @@ proto.handle = function handle(req, res, out) {
} else {
layer.handle_request(req, res, next);
}
sync = 0
}
};

View File

@ -78,7 +78,23 @@ describe('Router', function(){
router.handle({ url: '/', method: 'GET' }, { end: done });
});
it('should not stack overflow with a large sync stack', function (done) {
it('should not stack overflow with a large sync route stack', function (done) {
this.timeout(5000) // long-running test
var router = new Router()
for (var i = 0; i < 6000; i++) {
router.get('/foo', function (req, res, next) { next() })
}
router.get('/foo', function (req, res) {
res.end()
})
router.handle({ url: '/foo', method: 'GET' }, { end: done })
})
it('should not stack overflow with a large sync middleware stack', function (done) {
this.timeout(5000) // long-running test
var router = new Router()