Permalink
Browse files

fix _getEntries race condition

  • Loading branch information...
1 parent c7b7ee1 commit d039fa8f7727e65f8e10c0a074257460b142d9a3 @isaacs isaacs committed Mar 27, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 lib/dir-reader.js
View
@@ -39,6 +39,12 @@ function DirReader (props) {
DirReader.prototype._getEntries = function () {
var me = this
+
+ // race condition. might pause() before calling _getEntries,
+ // and then resume, and try to get them a second time.
+ if (me._gotEntries) return
+ me._gotEntries = true
+
fs.readdir(me._path, function (er, entries) {
if (er) return me.error(er)
@@ -229,9 +235,7 @@ DirReader.prototype.resume = function (who) {
}
if (me._currentEntry) {
- if (me._currentEntry.resume) {
- me._currentEntry.resume(who)
- }
+ if (me._currentEntry.resume) me._currentEntry.resume(who)
} else me._read()
}

0 comments on commit d039fa8

Please sign in to comment.