Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(userstatus): catch unique constrain violation on revert #45055

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions apps/dav/lib/CalDAV/Status/StatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Calendar\IManager;
use OCP\DB\Exception;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IUser as User;
Expand Down Expand Up @@ -72,7 +73,18 @@ public function processCalendarStatus(string $userId): void {
}

if(empty($calendarEvents)) {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
try {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
// A different process might have written another status
// update to the DB while we're processing our stuff.
// We cannot safely restore the status as we don't know which one is valid at this point
// So let's silently log this one and exit
$this->logger->debug('Unique constraint violation for live user status', ['exception' => $e]);
return;
}
}
$this->logger->debug('No calendar events found for status check', ['user' => $userId]);
return;
}
Expand Down Expand Up @@ -118,7 +130,18 @@ public function processCalendarStatus(string $userId): void {
});

if(empty($applicableEvents)) {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
try {
$this->userStatusService->revertUserStatus($userId, IUserStatus::MESSAGE_CALENDAR_BUSY);
} catch (Exception $e) {
if ($e->getReason() === Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
// A different process might have written another status
// update to the DB while we're processing our stuff.
// We cannot safely restore the status as we don't know which one is valid at this point
// So let's silently log this one and exit
$this->logger->debug('Unique constraint violation for live user status', ['exception' => $e]);
return;
}
}
$this->logger->debug('No status relevant events found, skipping calendar status change', ['user' => $userId]);
return;
}
Expand Down