fix: race condition in os.makedirs causing worker crashes
All checks were successful
git-sync-with-mirror / git-sync (push) Successful in 13s
CI / test (push) Successful in 47s

Replace check-then-create pattern with exist_ok=True to prevent
FileExistsError when multiple workers initialize simultaneously.

Affects:
- subscriptions.py: open_database()
- watch.py: save_decrypt_cache()
- local_playlist.py: add_to_playlist()
- util.py: fetch_url(), get_visitor_data()
- settings.py: initialization

Fixes Gunicorn worker startup failures in multi-worker deployments.
This commit is contained in:
2026-03-28 16:06:47 -05:00
parent a0d10e6a00
commit fa7273b328
5 changed files with 7 additions and 15 deletions

View File

@@ -453,8 +453,7 @@ else:
print("Running in non-portable mode")
settings_dir = os.path.expanduser(os.path.normpath("~/.yt-local"))
data_dir = os.path.expanduser(os.path.normpath("~/.yt-local/data"))
if not os.path.exists(settings_dir):
os.makedirs(settings_dir)
os.makedirs(settings_dir, exist_ok=True)
settings_file_path = os.path.join(settings_dir, 'settings.txt')