From a65f9b49eb3111638fc6df7394e83db29456a7c5 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 10 May 2017 01:14:52 +0200 Subject: [PATCH] Fix in session file locking --- paramecio/citoplasma/sessions.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/paramecio/citoplasma/sessions.py b/paramecio/citoplasma/sessions.py index e1468d7..3b9e420 100644 --- a/paramecio/citoplasma/sessions.py +++ b/paramecio/citoplasma/sessions.py @@ -5,6 +5,7 @@ from paramecio.citoplasma.keyutils import create_key_encrypt, create_key_encrypt from bottle import request, response import os import json +import fcntl try: @@ -202,7 +203,23 @@ else: path_cookie=config.session_opts['session.data_dir']+'/session_'+token with open(path_cookie, 'w') as f: + + #Lock file, if cannot lock wait + + while True: + try: + fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB) + break + except IOError as e: + # raise on unrelated IOErrors + if e.errno != errno.EAGAIN: + raise + else: + time.sleep(0.1) + f.write(json.dumps(session)) + + fcntl.flock(f, fcntl.LOCK_UN) """ def generate_session():