Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Service/Search/MailSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use OCA\Mail\Db\Message;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\MailboxLockedException;
use OCA\Mail\Exception\MailboxNotCachedException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\IMAP\PreviewEnhancer;
Expand Down Expand Up @@ -77,9 +76,12 @@ public function findMessages(Account $account,
?int $limit,
?string $userId,
?string $view): array {
if ($mailbox->hasLocks($this->timeFactory->getTime())) {
throw MailboxLockedException::from($mailbox);
}
// A mailbox sync lock coordinates concurrent *writes* (two sync
// attempts racing on the same mailbox); it was never a correctness
// requirement for a *read*. This method only ever reads from the
// local DB below (aside from an unrelated body-text-search path),
// so a mailbox mid-sync or currently locked can still be listed
// from its already-cached messages instead of failing outright.
if (!$mailbox->isCached()) {
throw MailboxNotCachedException::from($mailbox);
}
Expand Down
19 changes: 14 additions & 5 deletions tests/Unit/Service/Search/MailSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OCA\Mail\Db\Mailbox;
use OCA\Mail\Db\Message;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Exception\MailboxLockedException;
use OCA\Mail\Exception\MailboxNotCachedException;
use OCA\Mail\IMAP\PreviewEnhancer;
use OCA\Mail\IMAP\Search\Provider;
Expand Down Expand Up @@ -81,13 +80,21 @@ public function testFindMessagesNotCached() {
);
}

public function testFindMessagesLocked() {
$account = $this->createStub(Account::class);
public function testFindMessagesIgnoresLock() {
$account = $this->createMock(Account::class);
$account->expects($this->once())
->method('getUserId')
->willReturn('admin');
$mailbox = new Mailbox();
$mailbox->setSyncNewToken('abc');
$mailbox->setSyncChangedToken('def');
$mailbox->setSyncVanishedToken('ghi');
// A concurrent sync attempt is (or recently was) holding a lock on
// this mailbox -- findMessages() only reads already-cached
// messages, so it must not be blocked by it.
$mailbox->setSyncNewLock(123);
$this->expectException(MailboxLockedException::class);

$this->search->findMessages(
$messages = $this->search->findMessages(
$account,
$mailbox,
'DESC',
Expand All @@ -97,6 +104,8 @@ public function testFindMessagesLocked() {
null,
null,
);

$this->assertEmpty($messages);
}

public function testNoFindMessages() {
Expand Down