Skip to content

Commit

Permalink
Fix hanging on large stack of sync routes
Browse files Browse the repository at this point in the history
fixes #4899
  • Loading branch information
dougwilson committed Apr 29, 2022
1 parent 75e0c7a commit 631ada0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix hanging on large stack of sync routes

4.18.0 / 2022-04-25
===================

Expand Down
14 changes: 6 additions & 8 deletions lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down Expand Up @@ -327,8 +327,6 @@ proto.handle = function handle(req, res, out) {
} else {
layer.handle_request(req, res, next);
}

sync = 0
}
};

Expand Down
18 changes: 17 additions & 1 deletion test/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 631ada0

Please sign in to comment.