Skip to content
Myr

Fix regression routing a large stack in a single route

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #4913

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent ab2c70b · Browse files · 3 files+23 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−9 removed

  • tests:+10 added−1 removed
  • other:+13 added−8 removed

3 files+23 added−9 removed

modified:lib/router/route.js+8 added-8 removed
122 unmodified lines
123 if (err && err === 'router') {124 return done(err)125 }126127 var layer = stack[idx++];128 if (!layer) {129 return done(err);130 }131127 // max sync stack128 if (++sync > 100) {129 return setImmediate(next, err)130 }131137 if (layer.method && layer.method !== method) {138 return next(err);132 var layer = stack[idx++]133134 // end of layers135 if (!layer) {136 return done(err)137 }138141 if (err) {139 if (layer.method && layer.method !== method) {140 next(err)141 } else if (err) {142 layer.handle_error(err, req, res, next);143 } else {144 layer.handle_request(req, res, next);145 }
80 unmodified lines
modified:test/Route.js+10 added-1 removed
17 unmodified lines
1819 var req = { method: 'GET', url: '/' }20 var route = new Route('/foo')2122 route.get(function (req, res, next) {23 req.counter = 024 next()25 })2627 for (var i = 0; i < 6000; i++) {23 route.all(function (req, res, next) { next() })28 route.all(function (req, res, next) {29 req.counter++30 next()31 })32 }3334 route.get(function (req, res, next) {35 req.called = true
2 unmodified lines
3839 route.dispatch(req, {}, function (err) {40 if (err) return done(err)41 assert.ok(req.called)42 assert.strictEqual(req.counter, 6000)43 done()44 })45 })46
228 unmodified lines
modified:History.md+5 added
1unreleased2==========34 * Fix regression routing a large stack in a single route564.18.1 / 2022-04-297===================89 * Fix hanging on large stack of sync routes
3575 unmodified lines