Skip to content
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.

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

http: clean up dead code and unused properties #1572

Closed
wants to merge 1 commit into from

Conversation

mscdex
Copy link
Contributor

@mscdex mscdex commented May 1, 2015

No description provided.

stream.push(null);
}

if (stream && !parser.incoming._pendings.length) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only place I could find where ._pendings was actually used, so since nothing was ever added to the array, the second part of the conditional was always evaluating to true. Thus, the stream.push(null) can be merged up above.

@mscdex mscdex added the http Issues or PRs related to the http subsystem. label May 1, 2015
@@ -49,7 +47,6 @@ function IncomingMessage(socket) {
// response (client) only
this.statusCode = null;
this.statusMessage = null;
this.client = this.socket;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather we deprecate this property than delete it outright.

@chrisdickinson
Copy link
Contributor

Other than the deprecation preference, LGTM. _pendings appears to have been introduced by e6b6075, and superceded by streams2.

@mscdex
Copy link
Contributor Author

mscdex commented May 1, 2015

@chrisdickinson I added a deprecation notice for .client. Does that look alright?

@@ -63,6 +60,9 @@ util.inherits(IncomingMessage, Stream.Readable);

exports.IncomingMessage = IncomingMessage;

IncomingMessage.prototype.__defineGetter__('client', util.deprecate(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we prefer Object.defineProperty (like so, with a util.deprecate'd getter function as you have here), but otherwise this looks good!

@@ -613,8 +611,7 @@ OutgoingMessage.prototype._flush = function() {
var outputEncodings = this.outputEncodings;
var outputCallbacks = this.outputCallbacks;
for (var i = 0; i < outputLength; i++) {
ret = socket.write(output[i], outputEncodings[i],
outputCallbacks[i]);
ret = socket.write(output[i], outputEncodings[i], outputCallbacks[i]);
Copy link
Member

Choose a reason for hiding this comment

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

Can you undo the style changes in this file?

@bnoordhuis
Copy link
Member

LGTM with a request.

get: util.deprecate(function() {
return this.socket;
}, 'client is deprecated, use socket or connection instead')
});
Copy link
Contributor

Choose a reason for hiding this comment

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

might still want to support set here also if this is not semver-major

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would the setter do? Throw a deprecation error? Set this.socket? Set this.client again? Something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

would set this.socket. Could also throw a dep error I suppose.

@mscdex mscdex force-pushed the http-cleanup branch 2 times, most recently from 7fee207 to ebe5d52 Compare May 1, 2015 15:58
}, 'client is deprecated, use socket or connection instead'),
set: util.deprecate(function(val) {
this.socket = this.connection = val;
}, 'client is deprecated, use socket or connection instead')
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, just saw this. We should use set to change this.client to whatever the passed value is, while not affecting socket.

Copy link
Contributor

Choose a reason for hiding this comment

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

(As written this changes behavior – previously setting .client would not affect .socket.)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, so it should initially be set to this.socket then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, if the setter is changing this.client, wouldn't we have to change the underlying property name (e.g. to something like this._client) otherwise it would lead to some kind of loop (setting this.client inside a this.client setter)?

set: util.deprecate(function(val) {
this._client = val;
}, 'client is deprecated, use socket or connection instead')
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Of course, this will break if anyone is trying to do delete req.client for whatever reason..

@Fishrock123
Copy link
Contributor

LGTM, @chrisdickinson?

@brendanashworth
Copy link
Contributor

I think @chrisdickinson already signed off .

mscdex added a commit that referenced this pull request May 25, 2015
PR-URL: #1572
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
@mscdex
Copy link
Contributor Author

mscdex commented May 25, 2015

Landed in 1eec5f0.

@othiym23
Copy link
Contributor

I'd like to state for the record that I'm pretty annoyed that this landed in a non-semver major version of io.js, as it is, as we have seen in #1808 with request (and transitively npm), a breaking change. Whether or not properties of objects created within Node are considered part of the exported API or not, they are, and to change them or move them around is always at least a semver-major change, and should be trailed by a proper deprecation cycle, starting with notes in the documentation before any changes are made to the code.

As @ceejbot says here and here:

Properties on Node-created objects are part of the exported interface.

If you prefix them with _ and people use them, they get what they deserve. But if you didn’t, you’re stuck with them in perpetuity, sorry.

Just because client isn't used within the Node codebase doesn't mean it's not used in the ecosystem, and we don't get to decide how these things are consumed. It's hard to predict things like people using .hasOwnProperty(), so that part isn't so bad. But "cleanup" like this doesn't belong in minor or patch releases.

@Fishrock123
Copy link
Contributor

and should be trailed by a proper deprecation cycle, starting with notes in the documentation before any changes are made to the code.

I'm not up to date with #1704, but that contains the WIP deprecation policy, which you might be interested in.

http.IncomingRequest.client isn't documented anyways, and I doubt we are going to document a deprecation on something that isn't documented in the first place. A warning should do I think, and it shouldn't effect anything.

it's hard to predict things like people using .hasOwnProperty()

The core problem here was oversight of this point, not what you are making it to be.

But "cleanup" like this doesn't belong in minor or patch releases.

It landed in a minor, so far deprecations have been fine to land in minors?

If you prefix them with _ and people use them, they get what they deserve. But if you didn’t, you’re stuck with them in perpetuity, sorry.

This isn't actually correct. For example, there is no way we could possibly rename or change _headers. Way too much code depends on it. Again, I suggest discussing the deprecation policy.


In the mean time, we're tying to fix the actual oversight of .hasOwnProperty(): #1852

@othiym23
Copy link
Contributor

http.IncomingRequest.client isn't documented anyways

As I discuss below, its lack of documentation is immaterial to this discussion, and is also probably a bug in the documentation, strictly speaking.

and I doubt we are going to document a deprecation on something that isn't documented in the first place. A warning should do I think, and it shouldn't effect anything.

That seems to directly contradict the actual experience we're having right now.

But "cleanup" like this doesn't belong in minor or patch releases.

It landed in a minor, so far deprecations have been fine to land in minors?

I'm talking about the removal of client in the first place. That's a semver-major change, as client is part of the exported interface of the object, even if it's undocumented. I learn this with nearly every release of npm where we change some observable bit of npm's behavior: you can't predict what the community is going to be relying upon.

If you prefix them with _ and people use them, they get what they deserve. But if you didn’t, you’re stuck with them in perpetuity, sorry.

This isn't actually correct. For example, there is no way we could possibly rename or change _headers. Way too much code depends on it.

That's the converse of the quoted section's point – the important thing here is that properties are a part of the object's interface, documented or not. Expectations are higher on platforms than they are on tooling, and they're higher on tooling than they are on simple libraries or applications.

@Fishrock123
Copy link
Contributor

That seems to directly contradict the actual experience we're having right now.

Right, because we did it incorrect on a technical level and overlooked hasOwnProperty()

I'm talking about the removal of client in the first place.

I'm not really sure I'd consider replacing something with deprecation getter/setters as a "removal", but we still do have to be careful yes. However, as @mscdex mentioned to me in irc, doing things that don't work with getters, like delete client, in this case would have broken things beforehand anyways.

That's the converse of the quoted section's point – the important thing here is that properties are a part of the object's interface, documented or not.

Right, because I agree with the former, but _properties actually also are.

@ChALkeR
Copy link
Member

ChALkeR commented May 31, 2015

@Fishrock123 Deleting properties of the core objects was never supported and should never be used, it's an undefined behaviour. For example, delete res.socket will break things badly.

@ceejbot
Copy link

ceejbot commented May 31, 2015

Renaming properties on objects created by Node core modules should be considered a breaking change, whether prefixed with the conventional _ or not. The humble _ is a contract with the developer that says "here be dragons", so removing those is more defensible. It would not be prudent for node core to do it, however, particularly for things that have been around a long time.

The right fix is a process & tooling fix, so humans are not continually burdened by having to deal with this & think about the ramifications of every change. Part of the release acceptance should be a tool that runs npm install && npm test on a representative sample of, say, 20 modules that would make the ecosystem flip if they broke. Isaac talks about this in this comment on stability gates. (While getting the npm tests themselves to pass as part of this would be great, here the basic smoke test of npm install with a cold cache would have failed, if I understand correctly.)

I would be willing to help make this so.

@ChALkeR
Copy link
Member

ChALkeR commented May 31, 2015

@ceejbot I always thought that _-prefixed properties should be considered as «private», and that any changes to them would not be a semver-major. Except for the cases when it is known in advance that that will break things.

@Fishrock123
Copy link
Contributor

I would be willing to help make this so.

@ceejbot I've thought about having a suite of userland modules to test (As Rust is recently doing), however, to fully cover it there are two important points:

  • Also testing dependancies (easier)
  • Knowing how to run the tests for arbitrary modules (hard?)

Is there any way around the latter? I think we have access to more resources now to set something up like this, but I doubt I'll have time to work anything out in the next 2? weeks.

@chrisdickinson
Copy link
Contributor

Build is working on npm package smoke tests over here: nodejs/build#82

@mscdex
Copy link
Contributor Author

mscdex commented Jun 1, 2015

@Fishrock123 Shouldn't running tests be as simple as npm test?

@ceejbot
Copy link

ceejbot commented Jun 1, 2015

npm install & npm test should be enough to run the tests on any module you select as suitable for this project.

andrewdeandrade pushed a commit to andrewdeandrade/node that referenced this pull request Jun 3, 2015
PR-URL: nodejs/node#1572
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants