Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdenGD committed Nov 11, 2024
1 parent 370039c commit f92289f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = class Request extends Readable {
this._req.forEach((key, value) => {
this.#rawHeadersEntries.push([key, value]);
});
this.routeCount = 0;
this.key = key++;
if(key > 100000) {
key = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,13 @@ module.exports = class Router extends EventEmitter {
return this._routeRequest(req, res, 0, this._routes, false, skipUntil);
}
let callbackindex = 0;
const continueRoute = this._paramCallbacks.size === 0 ? this._preprocessRequest(req, res, route) : await this._preprocessRequest(req, res, route);

// avoid calling _preprocessRequest as async function as its slower
// but it seems like calling it as async has unintended consequence of resetting max call stack size
// so we only call it as async when the request has been through every 300 routes to reset it
const continueRoute = this._paramCallbacks.size === 0 && req.routeCount % 300 !== 0 ?
this._preprocessRequest(req, res, route) : await this._preprocessRequest(req, res, route);

if(route.use) {
const strictRouting = this.get('strict routing');
req._stack.push(route.path);
Expand Down Expand Up @@ -490,6 +496,7 @@ module.exports = class Router extends EventEmitter {
req.app = req.app.parent;
}
}
req.routeCount++;
return resolve(this._routeRequest(req, res, routeIndex + 1, routes, skipCheck, skipUntil));
} else {
this._handleError(thingamabob, req, res);
Expand Down

0 comments on commit f92289f

Please sign in to comment.