GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — net: do not inherit the no-half-open enforcer by lpinca · Pull Request #18974 · nodejs/node

net: do not inherit the no-half-open enforcer #18974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lpinca wants to merge 2 commits into nodejs:master from lpinca:avoid/inheriting-onend-listener

Uh oh!

There was an error while loading. Please reload this page.

Closed

net: do not inherit the no-half-open enforcer #18974

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
dc3969e
stream: make Duplex inherits from DuplexBase
lpinca Mar 5, 2018
5b73a79
net: do not inherit the no-half-open enforcer
lpinca Feb 24, 2018
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

26 changes: 4 additions & 22 deletions 26 lib/_stream_duplex.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,15 @@
module.exports = Duplex;

const util = require('util');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');

util.inherits(Duplex, Readable);

{
// avoid scope creep, the keys array can then be collected
const keys = Object.keys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
const method = keys[v];
if (!Duplex.prototype[method])
Duplex.prototype[method] = Writable.prototype[method];
}
}
const DuplexBase = require('internal/streams/duplex_base');

util.inherits(Duplex, DuplexBase);

function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);

Readable.call(this, options);
Writable.call(this, options);

if (options && options.readable === false)
this.readable = false;

if (options && options.writable === false)
this.writable = false;
DuplexBase.call(this, options);

this.allowHalfOpen = true;
if (options && options.allowHalfOpen === false) {
Expand Down
30 changes: 30 additions & 0 deletions 30 lib/internal/streams/duplex_base.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const util = require('util');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');

function DuplexBase(options) {
Readable.call(this, options);
Writable.call(this, options);

if (options && options.readable === false)
this.readable = false;

if (options && options.writable === false)
this.writable = false;
}

util.inherits(DuplexBase, Readable);

{
// Avoid scope creep, the keys array can then be collected.
const keys = Object.keys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
const method = keys[v];
if (!DuplexBase.prototype[method])
DuplexBase.prototype[method] = Writable.prototype[method];
}
}

module.exports = DuplexBase;
11 changes: 7 additions & 4 deletions 11 lib/net.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const {
ERR_SOCKET_BAD_PORT,
ERR_SOCKET_CLOSED
} = errors.codes;
const DuplexBase = require('internal/streams/duplex_base');
const dns = require('dns');

const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
Expand Down Expand Up @@ -238,7 +239,11 @@ function Socket(options) {
// For backwards compat do not emit close on destroy.
options.emitClose = false;

stream.Duplex.call(this, options);
// `DuplexBase` is just a slimmed down constructor for `Duplex` which allow
// us to not inherit the "no-half-open enforcer" as there is already one in
// place. Instances of `Socket` are still instances of `Duplex`, that is,
// `socket instanceof Duplex === true`.
DuplexBase.call(this, options);

if (options.handle) {
this._handle = options.handle; // private
Expand All @@ -263,8 +268,6 @@ function Socket(options) {
this._writev = null;
this._write = makeSyncWrite(fd);
}
this.readable = options.readable !== false;
this.writable = options.writable !== false;
} else {
// these will be set once there is a connection
this.readable = this.writable = false;
Expand All @@ -282,7 +285,7 @@ function Socket(options) {
this._writableState.decodeStrings = false;

// default to *not* allowing half open sockets
this.allowHalfOpen = options && options.allowHalfOpen || false;
this.allowHalfOpen = options.allowHalfOpen || false;
Comment thread Outdated

@addaleax addaleax Mar 4, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… and, as I understand it, would allow us to get rid of this, if we just transform allowHalfOpen correctly to begin with?

Also, I don’t know what the motivation for this was, but I don’t get why the default is not allowing half-open connections.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lpinca lpinca Mar 4, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated but options is always an object so there is no reason to see if it's truthy.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

// if we have a handle, then start the flow of data into the
// buffer. if not, then this will happen when we connect
Expand Down
1 change: 1 addition & 0 deletions 1 node.gyp
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'lib/internal/streams/lazy_transform.js',
'lib/internal/streams/async_iterator.js',
'lib/internal/streams/BufferList.js',
'lib/internal/streams/duplex_base.js',
'lib/internal/streams/duplexpair.js',
'lib/internal/streams/legacy.js',
'lib/internal/streams/destroy.js',
Expand Down
7 changes: 1 addition & 6 deletions 7 test/parallel/test-http-connect.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ server.listen(0, common.mustCall(() => {
assert.strictEqual(socket.listeners('connect').length, 0);
assert.strictEqual(socket.listeners('data').length, 0);
assert.strictEqual(socket.listeners('drain').length, 0);

// the stream.Duplex onend listener
// allow 0 here, so that i can run the same test on streams1 impl
assert(socket.listenerCount('end') <= 2,
`Found ${socket.listenerCount('end')} end listeners`);

assert.strictEqual(socket.listeners('end').length, 1);
assert.strictEqual(socket.listeners('free').length, 0);
assert.strictEqual(socket.listeners('close').length, 0);
assert.strictEqual(socket.listeners('error').length, 0);
Expand Down
11 changes: 11 additions & 0 deletions 11 test/parallel/test-net-socket-no-halfopen-enforcer.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
require('../common');

// This test ensures that `net.Socket` does not inherit the no-half-open
// enforcer from `stream.Duplex`.

const { Socket } = require('net');
const { strictEqual } = require('assert');

const socket = new Socket({ allowHalfOpen: false });
strictEqual(socket.listenerCount('end'), 1);
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.