Skip to content

Commit

Permalink
Don't increment the lock when the queue is empty.
Browse files Browse the repository at this point in the history
This will deadlock the entire loop.
  • Loading branch information
creationix committed Jun 30, 2010
1 parent 81d8d9f commit a7e2eb7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/nstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ function nStore(filename) {

var lock = 0;
function checkQueue() {
if (writeQueue.length === 0) { return; }
lock++;
if (lock > 1 || writeQueue.length === 0) { return; }
if (lock > 1) { return; }

// Merge the line buffers into a single large buffer
var buffer = new Buffer(queueSize);
Expand Down Expand Up @@ -198,7 +199,7 @@ function nStore(filename) {

// Unlock and try the loop again
lock = 0;
checkQueue();
process.nextTick(checkQueue);
});

}
Expand Down

0 comments on commit a7e2eb7

Please sign in to comment.