Skip to content
Myr

Fix hanging on large stack of sync routes

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

fixes #4899

authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 75e0c7a · Browse files · 3 files+28 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+28 added−9 removed

  • tests:+17 added−1 removed
  • other:+11 added−8 removed

3 files+28 added−9 removed

modified:lib/router/index.js+6 added-8 removed
277 unmodified lines
278279 // this should be done for the layer280 self.process_params(layer, paramcalled, req, res, function (err) {281 if (err) {282 return next(layerError || err);282 next(layerError || err)283 } else if (route) {284 layer.handle_request(req, res, next)285 } else {286 trim_prefix(layer, layerError, layerPath, path)287 }288285 if (route) {286 return layer.handle_request(req, res, next);287 }288289 trim_prefix(layer, layerError, layerPath, path);289 sync = 0290 });291 }292293 function trim_prefix(layer, layerError, layerPath, path) {
32 unmodified lines
326 layer.handle_error(layerError, req, res, next);327 } else {328 layer.handle_request(req, res, next);329 }330331 sync = 0330 }331};332333/**
340 unmodified lines
modified:test/Router.js+17 added-1 removed
76 unmodified lines
7778 router.handle({ url: '/', method: 'GET' }, { end: done });79 });8081 it('should not stack overflow with a large sync stack', function (done) {81 it('should not stack overflow with a large sync route stack', function (done) {82 this.timeout(5000) // long-running test8384 var router = new Router()8586 for (var i = 0; i < 6000; i++) {87 router.get('/foo', function (req, res, next) { next() })88 }8990 router.get('/foo', function (req, res) {91 res.end()92 })9394 router.handle({ url: '/foo', method: 'GET' }, { end: done })95 })9697 it('should not stack overflow with a large sync middleware stack', function (done) {98 this.timeout(5000) // long-running test99100 var router = new Router()101102 for (var i = 0; i < 6000; i++) {103 router.use(function (req, res, next) { next() })104 }105106 router.use(function (req, res) {
489 unmodified lines
modified:History.md+5 added
1unreleased2==========34 * Fix hanging on large stack of sync routes564.18.0 / 2022-04-257===================89 * Add "root" option to `res.download`
3570 unmodified lines