Skip to content

Commit

Permalink
Merge pull request #44778 from nextcloud/backport/44771/stable29
Browse files Browse the repository at this point in the history
[stable29] fix(federation): give some time to prepare both servers
  • Loading branch information
blizzz authored Apr 11, 2024
2 parents 884eb0c + f064883 commit 2617645
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions apps/federation/lib/BackgroundJob/RequestSharedSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected function run($argument) {
// if we received a unexpected response we try again later
if (
$status !== Http::STATUS_OK
&& $status !== Http::STATUS_FORBIDDEN
&& ($status !== Http::STATUS_FORBIDDEN || $this->getAttempt($argument) < 5)
) {
$this->retainJob = true;
}
Expand All @@ -173,14 +173,20 @@ protected function reAddJob(array $argument): void {
$url = $argument['url'];
$created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime();
$token = $argument['token'];
$attempt = $this->getAttempt($argument) + 1;

$this->jobList->add(
RequestSharedSecret::class,
[
'url' => $url,
'token' => $token,
'created' => $created
'created' => $created,
'attempt' => $attempt
]
);
}

protected function getAttempt(array $argument): int {
return $argument['attempt'] ?? 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function testStart($isTrustedServer, $retainBackgroundJob) {
'url' => 'url',
'token' => 'token',
'created' => 42,
'attempt' => 1,
]
);
} else {
Expand All @@ -164,12 +165,12 @@ public function dataTestStart() {
*
* @param int $statusCode
*/
public function testRun($statusCode) {
public function testRun(int $statusCode, int $attempt = 0): void {
$target = 'targetURL';
$source = 'sourceURL';
$token = 'token';

$argument = ['url' => $target, 'token' => $token];
$argument = ['url' => $target, 'token' => $token, 'attempt' => $attempt];

$this->timeFactory->method('getTime')->willReturn(42);

Expand All @@ -196,7 +197,7 @@ public function testRun($statusCode) {
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
if (
$statusCode !== Http::STATUS_OK
&& $statusCode !== Http::STATUS_FORBIDDEN
&& ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5)
) {
$this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
} else {
Expand All @@ -207,6 +208,7 @@ public function testRun($statusCode) {
public function dataTestRun() {
return [
[Http::STATUS_OK],
[Http::STATUS_FORBIDDEN, 5],
[Http::STATUS_FORBIDDEN],
[Http::STATUS_CONFLICT],
];
Expand Down

0 comments on commit 2617645

Please sign in to comment.