Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit c2fdd5c

Browse files
author
Olivier Gambier
committed
Enhance locking
Fixes various conditions failing and avoid being locked out if initialization fails.
1 parent e1cdaab commit c2fdd5c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docker_registry/toolkit.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import random
99
import re
1010
import string
11+
import time
1112
import urllib
1213

1314
import flask
@@ -299,14 +300,23 @@ def exclusive_lock(f):
299300
@functools.wraps(f)
300301
def wrapper(*args, **kwargs):
301302
lock_path = os.path.join(
302-
'/var/lock', 'registry.{0}.lock'.format(f.func_name)
303+
'./', 'registry.{0}.lock'.format(f.func_name)
303304
)
304305
if os.path.exists(lock_path):
306+
x = 0
307+
while os.path.exists(lock_path) and x < 100:
308+
logger.warn('Another process is creating the search database')
309+
x += 1
310+
time.sleep(1)
311+
if x == 100:
312+
raise Exception('Timedout waiting for db init')
305313
return
306314
lock_file = open(lock_path, 'w')
307315
lock_file.close()
308-
result = f(*args, **kwargs)
309-
os.remove(lock_path)
316+
try:
317+
result = f(*args, **kwargs)
318+
finally:
319+
os.remove(lock_path)
310320
return result
311321
return wrapper
312322

0 commit comments

Comments
 (0)