Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Object inherited from http.ClientRequest won't emit 'finish' #5758

Closed
biril opened this issue Jun 28, 2013 · 5 comments
Closed

Object inherited from http.ClientRequest won't emit 'finish' #5758

biril opened this issue Jun 28, 2013 · 5 comments
Labels

Comments

@biril
Copy link

biril commented Jun 28, 2013

var req = http.request("http://example.com", function () {});
req.on("finish", function () {
    console.log("finish");
});
req.end();

Will log "finish" but

var req = http.request("http://example.com", function () {});
req = Object.create(req);
req.on("finish", function () { // Never emitted
    console.log("finish"); 
});
req.end();

Will log nothing. Which I think is due to this check failing (taken from 10.12). Isn't this problematic?

@OrangeDog
Copy link

Why are you trying to do this? You probably want to either use a composition or a pipeline model, rather than inheritance.

@biril
Copy link
Author

biril commented Jun 28, 2013

No disagreement there, I could go about doing this differently.

However, I only managed to get an indication that I should do it differently by stepping through http.js. If there is some other indication that I shouldn't be doing this please do point me to it. Otherwise, the fact of the matter is that inheriting ClientRequest will break functionality in an unforeseen way. (It actually gave me quite a bit of grief when upgrading from 0.8). And it is in that sense that I view it as potentially problematic.

@chrisdickinson
Copy link

I can't reproduce this behavior on v0.11 or v0.10. The code given seems to hang due to response not being resumed, not due to the Object.create.

@biril
Copy link
Author

biril commented Nov 18, 2014

I still get the same behaviour on v0.10.21. First version will log 'finish', second version which includes req = Object.create(req); will not.

@indutny
Copy link
Member

indutny commented Nov 18, 2014

v0.10.21 is very very outdated, please check out nodejs.org website for the latest version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants