Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AIRFLOW-4248] Fix 'FileExistsError' makedirs() race condition #5047

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions airflow/utils/log/file_processor_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# specific language governing permissions and limitations
# under the License.

import errno
import logging
import os

Expand Down Expand Up @@ -49,9 +48,9 @@ def __init__(self, base_log_folder, filename_template):
if not os.path.exists(self._get_log_directory()):
try:
os.makedirs(self._get_log_directory())
except OSError as e:
except OSError:
# only ignore case where the directory already exist
if e.errno != errno.EEXIST:
if not os.path.isdir(self._get_log_directory()):
raise

logging.warning("%s already exists", self._get_log_directory())
Expand Down Expand Up @@ -138,7 +137,11 @@ def _init_file(self, filename):
directory = os.path.dirname(full_path)

if not os.path.exists(directory):
os.makedirs(directory)
try:
os.makedirs(directory)
except OSError:
if not os.path.isdir(directory):
raise

if not os.path.exists(full_path):
open(full_path, "a").close()
Expand Down