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

Write() after end() should raise an error? #8814

Closed
a0viedo opened this issue Dec 3, 2014 · 5 comments
Closed

Write() after end() should raise an error? #8814

a0viedo opened this issue Dec 3, 2014 · 5 comments

Comments

@a0viedo
Copy link
Member

a0viedo commented Dec 3, 2014

I was browsing the docs and found this:

Calling write() after calling end() will raise an error.

But, on branch v0.10, this code does nothing:

var http = require('http');
var server = http.createServer(function(req, res){
    res.write('hi');
    res.end();
    res.write('hi again');
});
server.listen(8080, function(){
    console.log('initialized');
});

This is a known bug or an expected behavior?

@cjihrig
Copy link

cjihrig commented Dec 3, 2014

This appears to have been fixed. If you try the same thing in 0.11.14, you should see something like this:

$ node foo.js 
initialized
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: write after end
    at ServerResponse.OutgoingMessage.write (_http_outgoing.js:409:15)
    at Server.<anonymous> (/private/tmp/foo.js:5:9)
    at Server.emit (events.js:110:17)
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:491:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
    at Socket.socketOnData (_http_server.js:343:22)
    at Socket.emit (events.js:107:17)
    at readableAddChunk (_stream_readable.js:162:16)
    at Socket.Readable.push (_stream_readable.js:125:10)
    at TCP.onread (net.js:514:20)

@a0viedo
Copy link
Member Author

a0viedo commented Dec 3, 2014

@cjihrig yeah I get the same on v0.11.14 but either way, that was the docs for v0.10.33. My plan was to know if it's going to be fixed on v0.10 branch or if the docs are going to change.

@cjihrig
Copy link

cjihrig commented Dec 5, 2014

The relevant issue is #7477, and the PR is #8422. I'm not sure what the plans are for the 0.10 branch are. Since it's a behavior change, I would think just a documentation update would do.

@misterdjules might be able to answer your question.

@misterdjules
Copy link

@cjihrig @a0viedo I also agree that we should fix the documentation not to use http.ServerResponse in the "write after end" example. Fixing the bug in the code would break backward compatibility, in the sense that a given Node.js program that is working with the current stable version could break with a new one containing this fix.

@a0viedo Would you like to send a PR to fix the documentation? That would be very much appreciated!

misterdjules pushed a commit to misterdjules/node that referenced this issue Dec 7, 2014
Currently there's an example using http.ServerResponse stream, which
has a known bug and will not throw an error while writing after end().
Changed to a writable stream from fs which behaves as expected.

fix nodejs#8814

Signed-off-by: Julien Gilli <julien.gilli@joyent.com>
@misterdjules
Copy link

Thank you @a0viedo! Fixed by f5cb330.

bnoordhuis pushed a commit to nodejs/node that referenced this issue Dec 14, 2014
Currently there's an example using http.ServerResponse stream, which
has a known bug and will not throw an error while writing after end().
Changed to a writable stream from fs which behaves as expected.

Fixes nodejs/node-v0.x-archive#8814.

PR-URL: #155
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Brendan Ashworth <squirrelslikeacorns@gmail.com>
mscdex pushed a commit to mscdex/node that referenced this issue Dec 25, 2014
Currently there's an example using http.ServerResponse stream, which
has a known bug and will not throw an error while writing after end().
Changed to a writable stream from fs which behaves as expected.

fix nodejs#8814

Signed-off-by: Julien Gilli <julien.gilli@joyent.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants