diff --git a/lib/classes/Swift/FileSpool.php b/lib/classes/Swift/FileSpool.php index d16c47cd6..6e0bc13fe 100644 --- a/lib/classes/Swift/FileSpool.php +++ b/lib/classes/Swift/FileSpool.php @@ -162,18 +162,25 @@ public function flushQueue(Swift_Transport $transport, &$failedRecipients = null continue; } - /* We try a rename, it's an atomic operation, and avoid locking the file */ + if (!$handle = @fopen($file, 'r+')) { + continue; + } + + if (!flock($handle, LOCK_EX | LOCK_NB )) { + /* This message has just been catched by another process */ + continue; + } if (rename($file, $file.'.sending')) { $message = unserialize(file_get_contents($file.'.sending')); + $count += $transport->send($message, $failedRecipients); unlink($file.'.sending'); - } else { - /* This message has just been catched by another process */ - continue; } + fclose ($handle); + if ($this->getMessageLimit() && $count >= $this->getMessageLimit()) { break; }