Skip to content

Commit eacd456

Browse files
authored
http: make TCP noDelay enabled by default
PR-URL: #42163 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 6b004f1 commit eacd456

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎doc/api/http.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,13 @@ Found'`.
28382838
<!-- YAML
28392839
added: v0.1.13
28402840
changes:
2841+
- version: REPLACEME
2842+
pr-url: https://github.com/nodejs/node/pull/42163
2843+
description: The `noDelay` option now defaults to `true`.
2844+
- version: REPLACEME
2845+
pr-url: https://github.com/nodejs/node/pull/41310
2846+
description: The `noDelay`, `keepAlive` and `keepAliveInitialDelay`
2847+
options are supported now.
28412848
- version:
28422849
- v13.8.0
28432850
- v12.15.0
@@ -2871,7 +2878,7 @@ changes:
28712878
**Default:** 16384 (16 KB).
28722879
*`noDelay` {boolean} If set to `true`, it disables the use of Nagle's
28732880
algorithm immediately after a new incoming connection is received.
2874-
**Default:**`false`.
2881+
**Default:**`true`.
28752882
*`keepAlive` {boolean} If set to `true`, it enables keep-alive functionality
28762883
on the socket immediately after a new incoming connection is received,
28772884
similarly on what is done in \[`socket.setKeepAlive([enable][, initialDelay])`]\[`socket.setKeepAlive(enable, initialDelay)`].

‎doc/api/net.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,10 @@ behavior.
822822
<!-- YAML
823823
added: v0.1.90
824824
changes:
825+
- version: REPLACEME
826+
pr-url: https://github.com/nodejs/node/pull/41310
827+
description: The `noDelay`, `keepAlive` and `keepAliveInitialDelay`
828+
options are supported now.
825829
- version: v12.10.0
826830
pr-url: https://github.com/nodejs/node/pull/25436
827831
description: Added `onread` option.

‎lib/_http_agent.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ function Agent(options) {
101101

102102
this.options={__proto__: null, ...options};
103103

104+
if(this.options.noDelay===undefined)
105+
this.options.noDelay=true;
106+
104107
// Don't confuse net and make it think that we're connecting to a pipe
105108
this.options.path=null;
106109
this.requests=ObjectCreate(null);

‎lib/_http_server.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ function storeHTTPOptions(options) {
363363
if(insecureHTTPParser!==undefined)
364364
validateBoolean(insecureHTTPParser,'options.insecureHTTPParser');
365365
this.insecureHTTPParser=insecureHTTPParser;
366+
367+
if(options.noDelay===undefined)
368+
options.noDelay=true;
366369
}
367370

368371
functionServer(options,requestListener){

‎test/parallel/test-http-nodelay.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constassert=require('assert');
5+
consthttp=require('http');
6+
constnet=require('net');
7+
8+
constoriginalConnect=net.Socket.prototype.connect;
9+
10+
net.Socket.prototype.connect=common.mustCall(function(args){
11+
assert.strictEqual(args[0].noDelay,true);
12+
returnoriginalConnect.call(this,args);
13+
});
14+
15+
constserver=http.createServer(common.mustCall((req,res)=>{
16+
res.writeHead(200);
17+
res.end();
18+
server.close();
19+
}));
20+
21+
server.listen(0,common.mustCall(()=>{
22+
assert.strictEqual(server.noDelay,true);
23+
24+
constreq=http.request({
25+
method: 'GET',
26+
port: server.address().port
27+
},common.mustCall((res)=>{
28+
res.on('end',()=>{
29+
server.close();
30+
res.req.socket.end();
31+
});
32+
33+
res.resume();
34+
}));
35+
36+
req.end();
37+
}));

0 commit comments

Comments
 (0)