Closes GH-535 Immediate pause/resume race condition

Calling resume() immediately after calling pause() would trigger
a race condition where it would try to read() from a file
descriptor that was already being read from, causing an EBADF
This commit is contained in:
isaacs 2011-03-29 14:54:49 -07:00 committed by Ryan Dahl
parent 4d64f36338
commit e1a72f0e2e
2 changed files with 10 additions and 2 deletions

View File

@ -838,7 +838,9 @@ ReadStream.prototype.setEncoding = function(encoding) {
ReadStream.prototype._read = function() {
var self = this;
if (!self.readable || self.paused) return;
if (!self.readable || self.paused || self.reading) return;
self.reading = true;
if (!pool || pool.length - pool.used < kMinPoolSpace) {
// discard the old pool. Can't add to the free list because
@ -864,6 +866,7 @@ ReadStream.prototype._read = function() {
}
function afterRead(err, bytesRead) {
self.reading = false;
if (err) {
self.emit('error', err);
self.readable = false;

View File

@ -42,8 +42,13 @@ file.addListener('open', function(fd) {
callbacks.open++;
assert.equal('number', typeof fd);
assert.ok(file.readable);
});
// GH-535
file.pause();
file.resume();
file.pause();
file.resume();
});
file.addListener('data', function(data) {
assert.ok(data instanceof Buffer);