Always call callbacks in lib/_http_outgoing.js#1143
Always call callbacks in lib/_http_outgoing.js#1143laino wants to merge 6 commits intonodejs:v1.xfrom laino:streamCallbacks
Conversation
There was a problem hiding this comment.
usually, a variable name of self would be used in this instance
|
I modified some code to make it adhere to the style used by io.js (proposed by @brendanashworth) |
|
Just found "make jslint", one more commit to make it pass that too. |
There was a problem hiding this comment.
It would be slightly more memory-efficient here and elsewhere to create the Error object inside the nextTick callback.
There was a problem hiding this comment.
The error object is created outside because otherwise it wouldn't contain the correct stack trace.
There was a problem hiding this comment.
I guess that's a fair point. What's the motivation for emitting the exception as an error instead of throwing it? Both are going to be disruptive.
As a small aside, I notice that OutgoingMessage#write() still returns true, indicating it's okay to call it again. That seems like a buglet to me.
There was a problem hiding this comment.
I left all return values unchanged. Currently return values are pretty much only used as an indicator of whether
the write had to be buffered (false) or was written instantly (true).
The reason for not throwing at that point is that the user still has no reliable (documented!) way of checking the state of the stream beforehand. He would have to wrap every write in try catch...
That's another thing bugging me about the state of the current stream API.
But even having to check some field every time before I do a write... nope! I'd rather handle all errors at one point: in my callback.
|
More micro-commits! |
|
So. Is this ready to get merged? Will it get merged? If not I'm ready to make the necessary changes. |
There was a problem hiding this comment.
is this check necessary? will a callback ever not be of type 'function'?
There was a problem hiding this comment.
It could be null or undefined if the user didn't specify one...
There was a problem hiding this comment.
So maybe just:
if (callback)
callback(err);|
I added some comments. Overall, I like what you've done with the code, but changing the tests to make them pass (as they didn't before? is this the case?) worries me. I'm unsure about the semver impact of this. |
|
I'd call not emitting/calling the callback with an error a bug. So this is a bugfix? I'm also confident that this will not break any existing code, as the callback is usually called when the write fails. This just fixes an edge case where it wasn't (which happens to be reproduced in the test). |
|
This PR is at least semver-minor, maybe semver-major. The big change is that HEAD responses with a body are now an error instead of a debug warning. It's pretty common for people to lump HEAD and GET responses together, even express.js used to do it at one time (and maybe it still does.) Looking at this PR again, it looks to me like a single commit that introduces two changes: one is that it forces callbacks to run always, the other is that it turns some warnings into errors. It's perhaps better to split it out so that the uncontroversial changes can at least go in. |
|
Mhh. Right. I forgot about that change while writing my response... I'll make the debug message -> error a separate PR. Edit: Which should get some discussion anyways. Should it even be an error or should the callback just be called indicating that the write succeeded? I think we can all agree that NOT I'm not sure what is be preferable, but the latter is a change that wouldn't break code which doesn't explicitly deal with HEAD requests (and is as such not a breaking change). |
|
Removed the controversial change from this PR |
There was a problem hiding this comment.
Style nit: please put a space after the slashes and use punctuation. I've been told some people take offense at gendered pronouns in comments.
I'm not sure how I feel about turning write-after-end into an error. It's arguably the proper thing to do but I worry that it's going to break a lot of existing code.
Fixes #1047
The changes will make sure that callbacks given to end() or write() will always be called, with or without an error depending on the circumstances.
A summary of the changes: