From fa7273b328b8cea8b051917f5255a1a712a9e1b9 Mon Sep 17 00:00:00 2001 From: Astounds Date: Sat, 28 Mar 2026 16:06:47 -0500 Subject: fix: race condition in os.makedirs causing worker crashes 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. --- youtube/watch.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'youtube/watch.py') diff --git a/youtube/watch.py b/youtube/watch.py index 360fbc9..332a9d5 100644 --- a/youtube/watch.py +++ b/youtube/watch.py @@ -329,11 +329,8 @@ def get_ordered_music_list_attributes(music_list): def save_decrypt_cache(): - try: - f = open(os.path.join(settings.data_dir, 'decrypt_function_cache.json'), 'w') - except FileNotFoundError: - os.makedirs(settings.data_dir) - f = open(os.path.join(settings.data_dir, 'decrypt_function_cache.json'), 'w') + os.makedirs(settings.data_dir, exist_ok=True) + f = open(os.path.join(settings.data_dir, 'decrypt_function_cache.json'), 'w') f.write(json.dumps({'version': 1, 'decrypt_cache':decrypt_cache}, indent=4, sort_keys=True)) f.close() -- cgit v1.2.3