0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-25 09:20:16 +00:00

fix(federation): always set server status to OK after successful runs

Previously if a server status got set to failure, it stayed that way
until an addressbook-sync found changes. Now the server status is set to
OK after each successful sync check (if that's not the case already),
regardless of addressbook changes.

This change also includes two new logging statements, which could help
next time someone debugs this.

Signed-off-by: Pablo Zimdahl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zimdahl 2024-08-22 10:22:30 +02:00 committed by backportbot[bot]
parent bb67798804
commit 04f313d1d6
4 changed files with 37 additions and 0 deletions

View file

@ -112,6 +112,7 @@ class GetSharedSecret extends Job {
// kill job after 30 days of trying
$deadline = $currentTime - $this->maxLifespan;
if ($created < $deadline) {
$this->logger->warning("The job to get the shared secret job is too old and gets stopped now without retention. Setting server status of '{$target}' to failure.");
$this->retainJob = false;
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
return;

View file

@ -116,6 +116,7 @@ class RequestSharedSecret extends Job {
// kill job after 30 days of trying
$deadline = $currentTime - $this->maxLifespan;
if ($created < $deadline) {
$this->logger->warning("The job to request the shared secret job is too old and gets stopped now without retention. Setting server status of '{$target}' to failure.");
$this->retainJob = false;
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
return;

View file

@ -78,6 +78,10 @@ class SyncFederationAddressBooks {
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
} else {
$this->logger->debug("Sync Token for $url unchanged from previous sync");
// The server status might have been changed to a failure status in previous runs.
if ($this->dbHandler->getServerStatus($url) !== TrustedServers::STATUS_OK) {
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK);
}
}
} catch (\Exception $ex) {
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {

View file

@ -111,4 +111,35 @@ class SyncFederationAddressbooksTest extends \Test\TestCase {
});
$this->assertEquals(2, count($this->callBacks));
}
public function testSuccessfulSyncWithoutChangesAfterFailure() {
/** @var DbHandler | MockObject $dbHandler */
$dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
->disableOriginalConstructor()
->getMock();
$dbHandler->method('getAllServer')
->willReturn([
[
'url' => 'https://cloud.drop.box',
'url_hash' => 'sha1',
'shared_secret' => 'ilovenextcloud',
'sync_token' => '0'
]
]);
$dbHandler->method('getServerStatus')->willReturn(\OCA\Federation\TrustedServers::STATUS_FAILURE);
$dbHandler->expects($this->once())->method('setServerStatus')->
with('https://cloud.drop.box', 1);
$syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
->disableOriginalConstructor()
->getMock();
$syncService->expects($this->once())->method('syncRemoteAddressBook')
->willReturn('0');
/** @var \OCA\DAV\CardDAV\SyncService $syncService */
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
$s->syncThemAll(function ($url, $ex) {
$this->callBacks[] = [$url, $ex];
});
$this->assertEquals('1', count($this->callBacks));
}
}