Skip to content

Commit da46741

Browse files
committed
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>
1 parent 0df3a46 commit da46741

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

apps/federation/lib/BackgroundJob/GetSharedSecret.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected function run($argument) {
9090
// kill job after 30 days of trying
9191
$deadline = $currentTime - $this->maxLifespan;
9292
if ($created < $deadline) {
93+
$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.");
9394
$this->retainJob = false;
9495
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
9596
return;

apps/federation/lib/BackgroundJob/RequestSharedSecret.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function run($argument) {
9393
// kill job after 30 days of trying
9494
$deadline = $currentTime - $this->maxLifespan;
9595
if ($created < $deadline) {
96+
$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.");
9697
$this->retainJob = false;
9798
$this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
9899
return;

apps/federation/lib/SyncFederationAddressBooks.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function syncThemAll(\Closure $callback) {
6060
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
6161
} else {
6262
$this->logger->debug("Sync Token for $url unchanged from previous sync");
63+
// The server status might have been changed to a failure status in previous runs.
64+
if ($this->dbHandler->getServerStatus($url) !== TrustedServers::STATUS_OK) {
65+
$this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK);
66+
}
6367
}
6468
} catch (\Exception $ex) {
6569
if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {

apps/federation/tests/SyncFederationAddressbooksTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,35 @@ public function testException() {
9090
});
9191
$this->assertEquals(2, count($this->callBacks));
9292
}
93+
94+
public function testSuccessfulSyncWithoutChangesAfterFailure() {
95+
/** @var DbHandler | MockObject $dbHandler */
96+
$dbHandler = $this->getMockBuilder('OCA\Federation\DbHandler')
97+
->disableOriginalConstructor()
98+
->getMock();
99+
$dbHandler->method('getAllServer')
100+
->willReturn([
101+
[
102+
'url' => 'https://cloud.drop.box',
103+
'url_hash' => 'sha1',
104+
'shared_secret' => 'ilovenextcloud',
105+
'sync_token' => '0'
106+
]
107+
]);
108+
$dbHandler->method('getServerStatus')->willReturn(\OCA\Federation\TrustedServers::STATUS_FAILURE);
109+
$dbHandler->expects($this->once())->method('setServerStatus')->
110+
with('https://cloud.drop.box', 1);
111+
$syncService = $this->getMockBuilder('OCA\DAV\CardDAV\SyncService')
112+
->disableOriginalConstructor()
113+
->getMock();
114+
$syncService->expects($this->once())->method('syncRemoteAddressBook')
115+
->willReturn('0');
116+
117+
/** @var \OCA\DAV\CardDAV\SyncService $syncService */
118+
$s = new SyncFederationAddressBooks($dbHandler, $syncService, $this->discoveryService, $this->logger);
119+
$s->syncThemAll(function ($url, $ex) {
120+
$this->callBacks[] = [$url, $ex];
121+
});
122+
$this->assertEquals('1', count($this->callBacks));
123+
}
93124
}

0 commit comments

Comments
 (0)