Skip to content

Commit 2617645

Browse files
authored
Merge pull request #44778 from nextcloud/backport/44771/stable29
[stable29] fix(federation): give some time to prepare both servers
2 parents 884eb0c + f064883 commit 2617645

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

apps/federation/lib/BackgroundJob/RequestSharedSecret.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function run($argument) {
160160
// if we received a unexpected response we try again later
161161
if (
162162
$status !== Http::STATUS_OK
163-
&& $status !== Http::STATUS_FORBIDDEN
163+
&& ($status !== Http::STATUS_FORBIDDEN || $this->getAttempt($argument) < 5)
164164
) {
165165
$this->retainJob = true;
166166
}
@@ -173,14 +173,20 @@ protected function reAddJob(array $argument): void {
173173
$url = $argument['url'];
174174
$created = isset($argument['created']) ? (int)$argument['created'] : $this->time->getTime();
175175
$token = $argument['token'];
176+
$attempt = $this->getAttempt($argument) + 1;
176177

177178
$this->jobList->add(
178179
RequestSharedSecret::class,
179180
[
180181
'url' => $url,
181182
'token' => $token,
182-
'created' => $created
183+
'created' => $created,
184+
'attempt' => $attempt
183185
]
184186
);
185187
}
188+
189+
protected function getAttempt(array $argument): int {
190+
return $argument['attempt'] ?? 0;
191+
}
186192
}

apps/federation/tests/BackgroundJob/RequestSharedSecretTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function testStart($isTrustedServer, $retainBackgroundJob) {
142142
'url' => 'url',
143143
'token' => 'token',
144144
'created' => 42,
145+
'attempt' => 1,
145146
]
146147
);
147148
} else {
@@ -164,12 +165,12 @@ public function dataTestStart() {
164165
*
165166
* @param int $statusCode
166167
*/
167-
public function testRun($statusCode) {
168+
public function testRun(int $statusCode, int $attempt = 0): void {
168169
$target = 'targetURL';
169170
$source = 'sourceURL';
170171
$token = 'token';
171172

172-
$argument = ['url' => $target, 'token' => $token];
173+
$argument = ['url' => $target, 'token' => $token, 'attempt' => $attempt];
173174

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

@@ -196,7 +197,7 @@ public function testRun($statusCode) {
196197
$this->invokePrivate($this->requestSharedSecret, 'run', [$argument]);
197198
if (
198199
$statusCode !== Http::STATUS_OK
199-
&& $statusCode !== Http::STATUS_FORBIDDEN
200+
&& ($statusCode !== Http::STATUS_FORBIDDEN || $attempt < 5)
200201
) {
201202
$this->assertTrue($this->invokePrivate($this->requestSharedSecret, 'retainJob'));
202203
} else {
@@ -207,6 +208,7 @@ public function testRun($statusCode) {
207208
public function dataTestRun() {
208209
return [
209210
[Http::STATUS_OK],
211+
[Http::STATUS_FORBIDDEN, 5],
210212
[Http::STATUS_FORBIDDEN],
211213
[Http::STATUS_CONFLICT],
212214
];

0 commit comments

Comments
 (0)