Skip to content

Commit 87a6a8a

Browse files
authored
Retry certification fetch if the first attempt fails (#670)
1 parent 473224c commit 87a6a8a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

matter_server/server/helpers/paa_certificates.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import asyncio
1111
from datetime import UTC, datetime, timedelta
1212
import logging
13-
from os import makedirs
13+
import os
1414
from pathlib import Path
1515
import re
1616

@@ -162,7 +162,13 @@ async def fetch_certificates(
162162
loop = asyncio.get_running_loop()
163163

164164
if not paa_root_cert_dir.is_dir():
165-
await loop.run_in_executor(None, makedirs, paa_root_cert_dir)
165+
166+
def _make_root_cert_dir(paa_root_cert_dir: Path) -> None:
167+
paa_root_cert_dir.mkdir(parents=True)
168+
# Clear mtime to make sure code retries if first fetch fails.
169+
os.utime(paa_root_cert_dir, (0, 0))
170+
171+
await loop.run_in_executor(None, _make_root_cert_dir, paa_root_cert_dir)
166172
else:
167173
stat = await loop.run_in_executor(None, paa_root_cert_dir.stat)
168174
last_fetch = datetime.fromtimestamp(stat.st_mtime, tz=UTC)

0 commit comments

Comments
 (0)