From 1328c0960d5e561819f79a04483ff5b88e77df69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luis=20Gonz=C3=A1lez?= <lgonzalez@vauxoo.com>
Date: Tue, 17 Apr 2018 13:17:47 +0200
Subject: [PATCH] [IMP] tools: avoid concurrent creation of the session_dir

Instead of:
1. testing the existance
2. creating the directory if not exists

(which would not work if a concurrent creation is done between step 1 and 2)

do:
1. try to create the directory
2. skip if it fails

Ask forgiveness, not permission

Closes #24210
---
 odoo/tools/config.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/odoo/tools/config.py b/odoo/tools/config.py
index ec7cc0c0cb1b..5e925aba0e2e 100644
--- a/odoo/tools/config.py
+++ b/odoo/tools/config.py
@@ -6,6 +6,7 @@ try:
 except ImportError:
     import ConfigParser
 
+import errno
 import logging
 import optparse
 import os
@@ -620,9 +621,11 @@ class configmanager(object):
     @property
     def session_dir(self):
         d = os.path.join(self['data_dir'], 'sessions')
-        if not os.path.exists(d):
+        try:
             os.makedirs(d, 0o700)
-        else:
+        except OSError as e:
+            if e.errno != errno.EEXIST:
+                raise
             assert os.access(d, os.W_OK), \
                 "%s: directory is not writable" % d
         return d
-- 
GitLab