Skip to content

Commit 359b1ae

Browse files
committed
net: skip chunk check on incoming data
Do not validate data chunks read from the socket handle as they are guaranteed to be buffers and validation is costly.
1 parent f651d6c commit 359b1ae

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/net.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ function Socket(options) {
239239
// For backwards compat do not emit close on destroy.
240240
options.emitClose = false;
241241

242+
// Data chunks read from the handle are always buffers so there is no need to
243+
// validate them.
244+
options.skipChunkCheck = true;
245+
242246
// `DuplexBase` is just a slimmed down constructor for `Duplex` which allow
243247
// us to not inherit the "no-half-open enforcer" as there is already one in
244248
// place. Instances of `Socket` are still instances of `Duplex`, that is,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
require('../common');
3+
4+
// This test ensures that `net.Socket` uses the `skipChunkCheck` option
5+
// when calling the `Readable` constructor.
6+
7+
const { Socket } = require('net');
8+
const { strictEqual } = require('assert');
9+
10+
const socket = new Socket();
11+
strictEqual(socket._readableState.skipChunkCheck, true);

0 commit comments

Comments
 (0)