v2.5.0: harden telemt user reloads

This commit is contained in:
Виталий Литвинов
2026-04-25 17:50:06 +03:00
parent 5a6bc9f614
commit 2f3607e1e6
5 changed files with 85 additions and 2 deletions

View File

@@ -279,6 +279,8 @@ _DOMAIN_RE = re.compile(
)
_USER_NAME_RE = re.compile(r"^[A-Za-z0-9_.-]{1,48}$")
MAX_UNIQUE_IP_LIMIT = 1000000
TELEMT_RESTART_DEBOUNCE_SECONDS = float(os.getenv("GOTELEGRAM_TELEMT_RESTART_DEBOUNCE", "8"))
_LAST_TELEMT_RESTART = 0.0
class FileLock:
@@ -1638,7 +1640,15 @@ def save_telemt_users(users: Dict[str, str]) -> bool:
async def refresh_telemt_after_user_change() -> bool:
"""Restart telemt after config user changes."""
"""Restart telemt after config user changes, coalescing rapid UI clicks."""
global _LAST_TELEMT_RESTART
now = time.monotonic()
if _LAST_TELEMT_RESTART > 0 and now - _LAST_TELEMT_RESTART < TELEMT_RESTART_DEBOUNCE_SECONDS:
code, stdout, _ = await sh("systemctl", "is-active", TELEMT_SERVICE, timeout=5)
if code == 0 and stdout.strip() == "active":
return True
await sh("systemctl", "reset-failed", TELEMT_SERVICE, timeout=5)
_LAST_TELEMT_RESTART = now
code, _, _ = await sh("systemctl", "--no-block", "restart", TELEMT_SERVICE, timeout=5)
return code == 0