Skip to content

Commit c69628e

Browse files
authored
Merge pull request #7821 from LibreSign/fix/cfssl-startup-transient-failures
fix: avoid failing on transient CFSSL startup errors
2 parents fb7a1f7 + fd31a19 commit c69628e

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

lib/Handler/CertificateEngine/CfsslHandler.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private function isUp(): bool {
281281
try {
282282
$client = $this->getClient();
283283
if (!$this->portOpen()) {
284-
throw new LibresignException('CFSSL server is down', 500);
284+
return false;
285285
}
286286
$response = $client
287287
->request('get',
@@ -291,24 +291,18 @@ private function isUp(): bool {
291291
]
292292
)
293293
;
294-
} catch (RequestException|ConnectException $th) {
295-
switch ($th->getCode()) {
296-
case 404:
297-
throw new \Exception('Endpoint /health of CFSSL server not found. Maybe you are using incompatible version of CFSSL server. Use latests version.', 1);
298-
default:
299-
if ($th->getHandlerContext() && $th->getHandlerContext()['error']) {
300-
throw new \Exception($th->getHandlerContext()['error'], 1);
301-
}
302-
throw new LibresignException($th->getMessage(), 500);
294+
} catch (ConnectException) {
295+
// Port not yet accepting connections — server still starting
296+
return false;
297+
} catch (RequestException $exception) {
298+
if ($exception->getCode() === 404) {
299+
throw new \Exception('Endpoint /health of CFSSL server not found. Maybe you are using incompatible version of CFSSL server. Use latests version.', 1);
303300
}
301+
return false;
304302
}
305303

306304
$responseDecoded = json_decode((string)$response->getBody(), true);
307-
if (!isset($responseDecoded['success']) || !$responseDecoded['success']) {
308-
throw new LibresignException('Error while check cfssl API health!', 500);
309-
}
310-
311-
if (empty($responseDecoded['result']) || empty($responseDecoded['result']['healthy'])) {
305+
if (empty($responseDecoded['result']['healthy'])) {
312306
return false;
313307
}
314308

@@ -346,7 +340,7 @@ private function wakeUp(): void {
346340
}
347341

348342
$loops = 0;
349-
while (!$this->portOpen() && $loops <= 4) {
343+
while (!$this->portOpen() && $loops <= 9) {
350344
sleep(1);
351345
$loops++;
352346
}

0 commit comments

Comments
 (0)