Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit e1a72f0e2e4fa668d73657c55ed399f674af6ec0 1 parent 4d64f36
@isaacs isaacs authored ry committed
Showing with 10 additions and 2 deletions.
  1. +4 −1 lib/fs.js
  2. +6 −1 test/simple/test-fs-read-stream.js
View
5 lib/fs.js
@@ -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
7 test/simple/test-fs-read-stream.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.