Skip to content

Commit

Permalink
Merge pull request #322 from ackintosh/race-condition
Browse files Browse the repository at this point in the history
Fix race condition in FlatFileDriver::popMessage()
  • Loading branch information
henrikbjorn authored Aug 17, 2017
2 parents 5681d3e + a1f98f0 commit 0a53868
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Driver/FlatFileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ public function popMessage($queueName, $duration = 5)
while (microtime(true) < $runtime) {
if ($files) {
$id = array_pop($files);
$data = array(file_get_contents($queueDir.DIRECTORY_SEPARATOR.$id), $id);
rename($queueDir.DIRECTORY_SEPARATOR.$id, $queueDir.DIRECTORY_SEPARATOR.$id.'.proceed');

return $data;
if (@rename($queueDir.DIRECTORY_SEPARATOR.$id, $queueDir.DIRECTORY_SEPARATOR.$id.'.proceed')) {
return array(file_get_contents($queueDir.DIRECTORY_SEPARATOR.$id.'.proceed'), $id);
}
}

usleep(1000);
Expand Down

0 comments on commit 0a53868

Please sign in to comment.