Skip to content

Commit

Permalink
syncronous inflightRequest calc
Browse files Browse the repository at this point in the history
  • Loading branch information
retrohacker committed Mar 14, 2019
1 parent 7db83a5 commit b889324
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/server.js
Expand Up @@ -217,12 +217,14 @@ function Server(options) {
return;
}

self._inflightRequests++;
if (!options.noWriteContinue) {
res.writeContinue();
}

self.earliestChain.run(req, res, function earliestDone(ignore) {
if (ignore === false || Boolean(ignore)) {
self._inflightRequests--;
return;
}
self._onRequest(req, res);
Expand All @@ -231,10 +233,12 @@ function Server(options) {

if (options.handleUpgrades) {
this.server.on('upgrade', function onUpgrade(req, socket, head) {
self._inflightRequests++;
var res = upgrade.createResponse(req, socket, head);
req._upgradeRequest = true;
self.earliestChain.run(req, res, function earliestDone(ignore) {
if (ignore === false || Boolean(ignore)) {
self._inflightRequests--;
return;
}
self._onRequest(req, res);
Expand All @@ -243,8 +247,10 @@ function Server(options) {
}

this.server.on('request', function onRequest(req, res) {
self._inflightRequests++;
self.earliestChain.run(req, res, function earliestDone(ignore) {
if (ignore === false || Boolean(ignore)) {
self._inflightRequests--;
return;
}

Expand Down Expand Up @@ -897,9 +903,6 @@ Server.prototype._onRequest = function _onRequest(req, res) {
// Decorate req and res objects
self._setupRequest(req, res);

// increment number of requests
self._inflightRequests++;

// Run in domain to catch async errors
// It has significant negative performance impact
// Warning: this feature depends on the deprecated domains module
Expand Down

0 comments on commit b889324

Please sign in to comment.