GeezerVison is showing github.com — http: guard invalid timeout values in checkConnections · nodejs/node@6794441
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_http_server.js +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -739,11 +739,18 @@ assignFunctionName(EE.captureRejectionSymbol, function(err, event, ...args) { |
739 | 739 | }); |
740 | 740 |
|
741 | 741 | function checkConnections() { |
742 | | - if (this.headersTimeout === 0 && this.requestTimeout === 0) { |
| 742 | + const headersTimeout = |
| 743 | + NumberIsFinite(this.headersTimeout) && this.headersTimeout >= 0 ? |
| 744 | + this.headersTimeout : 0; |
| 745 | + const requestTimeout = |
| 746 | + NumberIsFinite(this.requestTimeout) && this.requestTimeout >= 0 ? |
| 747 | + this.requestTimeout : 0; |
| 748 | + |
| 749 | + if (headersTimeout === 0 && requestTimeout === 0) { |
743 | 750 | return; |
744 | 751 | } |
745 | 752 |
|
746 | | - const expired = this[kConnections].expired(this.headersTimeout, this.requestTimeout); |
| 753 | + const expired = this[kConnections].expired(headersTimeout, requestTimeout); |
747 | 754 |
|
748 | 755 | for (let i = 0; i < expired.length; i++) { |
749 | 756 | const socket = expired[i].socket; |
|
Collapse file
Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const { createServer } = require('http'); |
| 6 | + |
| 7 | +const server = createServer({ |
| 8 | + connectionsCheckingInterval: 1, |
| 9 | +}, common.mustNotCall()); |
| 10 | + |
| 11 | +// Invalid headersTimeout should not crash the server |
| 12 | +server.headersTimeout = 'im-not-a-number'; |
| 13 | +assert.strictEqual(server.headersTimeout, 'im-not-a-number'); |
| 14 | + |
| 15 | +server.listen(0, '127.0.0.1', common.mustCall(() => { |
| 16 | + setTimeout(common.mustCall(() => { |
| 17 | + server.close(common.mustCall()); |
| 18 | + }), common.platformTimeout(50)); |
| 19 | +})); |