mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-17 10:15:27 -04:00
fix: add _setup_lock to prevent race condition in first-run setup (#508)
This commit is contained in:
@@ -60,6 +60,9 @@ class AuthManager:
|
|||||||
# Guards mutations of self._sessions and the on-disk sessions.json.
|
# Guards mutations of self._sessions and the on-disk sessions.json.
|
||||||
# Validate/create/revoke run concurrently from the FastAPI threadpool.
|
# Validate/create/revoke run concurrently from the FastAPI threadpool.
|
||||||
self._sessions_lock = threading.RLock()
|
self._sessions_lock = threading.RLock()
|
||||||
|
# Guards the first-run setup check-and-write so concurrent requests
|
||||||
|
# cannot both observe is_configured==False and both create admin accounts.
|
||||||
|
self._setup_lock = threading.Lock()
|
||||||
self._load()
|
self._load()
|
||||||
self._load_sessions()
|
self._load_sessions()
|
||||||
self._migrate_single_user()
|
self._migrate_single_user()
|
||||||
@@ -157,6 +160,7 @@ class AuthManager:
|
|||||||
|
|
||||||
def setup(self, username: str, password: str) -> bool:
|
def setup(self, username: str, password: str) -> bool:
|
||||||
"""First-run admin setup. Only works if no users exist."""
|
"""First-run admin setup. Only works if no users exist."""
|
||||||
|
with self._setup_lock:
|
||||||
if self.is_configured:
|
if self.is_configured:
|
||||||
return False
|
return False
|
||||||
return self.create_user(username, password, is_admin=True)
|
return self.create_user(username, password, is_admin=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user