Skip to content

Commit

Permalink
Retry certification fetch if the first attempt fails (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners committed Apr 22, 2024
1 parent 473224c commit 87a6a8a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions matter_server/server/helpers/paa_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import asyncio
from datetime import UTC, datetime, timedelta
import logging
from os import makedirs
import os
from pathlib import Path
import re

Expand Down Expand Up @@ -162,7 +162,13 @@ async def fetch_certificates(
loop = asyncio.get_running_loop()

if not paa_root_cert_dir.is_dir():
await loop.run_in_executor(None, makedirs, paa_root_cert_dir)

def _make_root_cert_dir(paa_root_cert_dir: Path) -> None:
paa_root_cert_dir.mkdir(parents=True)
# Clear mtime to make sure code retries if first fetch fails.
os.utime(paa_root_cert_dir, (0, 0))

await loop.run_in_executor(None, _make_root_cert_dir, paa_root_cert_dir)
else:
stat = await loop.run_in_executor(None, paa_root_cert_dir.stat)
last_fetch = datetime.fromtimestamp(stat.st_mtime, tz=UTC)
Expand Down

0 comments on commit 87a6a8a

Please sign in to comment.