This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
In http.Agent, response.readable is never set to false, causing bugs in response.pipe() #867
Closed
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5e576f3
Fix bug where http response.readable was never set to false
abram 7e26fa9
return false instead of emitting pause to indicate that pipe should w…
abram e8ecfa8
Merge branch 'master' of https://github.com/joyent/node
abram fe82627
Use simpler test case
abram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var http = require('http'); | ||
var stream = require('stream'); | ||
var util = require('util'); | ||
|
||
function SlowStream() { | ||
stream.Stream.call(this); | ||
this.writable = true; | ||
this.output = ''; | ||
} | ||
util.inherits(SlowStream, stream.Stream); | ||
|
||
SlowStream.prototype.write = function(buffer) { | ||
this.output += buffer.toString(); | ||
console.log('wrote data.'); | ||
var self = this; | ||
this.emit('pause'); | ||
setTimeout(function() { | ||
self.emit('drain'); | ||
}, 100); | ||
}; | ||
|
||
SlowStream.prototype.end = function() { | ||
testServer.close(); | ||
}; | ||
|
||
var chunks = ['hello ', 'world']; | ||
|
||
var testServer = new http.Server(function(req, res) { | ||
res.writeHead(200); | ||
res.write(chunks[0]); | ||
process.nextTick(function() { | ||
res.write(chunks[1]); | ||
process.nextTick(function() { | ||
res.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
testServer.listen(common.PORT); | ||
|
||
var outputStream = new SlowStream(); | ||
|
||
var request = http.get({ | ||
host: 'localhost', | ||
port: common.PORT, | ||
path: '/', | ||
}, function(response) { | ||
response.on('data', function() { console.log('got some data'); }); | ||
// If response.readable isn't being properly set to false, this will | ||
// cause an error, because the final time .resume() is called on the | ||
// response the underlying socket will already be closed. | ||
response.pipe(outputStream); | ||
}); | ||
request.end(); | ||
|
||
process.addListener('exit', function() { | ||
assert.equal(outputStream.output, chunks.join('')); | ||
}); |
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.
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.
You shouldn't need to emit
pause
on a writable stream. Returningfalse
from the write function will in turn make the read stream call pause on itself. See theStream#pipe()
source to see what I'm talking about.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.
Thanks for pointing that out. Updated to return false instead of emitting 'pause'. This doesn't change the behavior of the test case in demonstrating the bug.