Skip to content

Commit

Permalink
[AIRFLOW-4248] Fix 'FileExistsError' makedirs race in file_processor_…
Browse files Browse the repository at this point in the history
…handler (#5047)
  • Loading branch information
kppullin authored and ashb committed Apr 5, 2019
1 parent eb4d3ec commit 45270cd
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 45270cd

Please sign in to comment.