Commit f47c63be authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

fix race condition

parent 772f9100
......@@ -1110,7 +1110,8 @@ class JobManager(Manager):
# pull the image to the swarm
if info.ver_id is not None:
# FIXME: race condition: will fail if ver.state==sandbox
# NOTE: race condition: will fail if ver.state==sandbox
# jobs must be submitted after the image is committed
yield from ctrl.image_manager.pull(info.ver_id, swarm=True)
# lock the semaphore (to limit the total number of jobs)
......@@ -1187,6 +1188,8 @@ class PushManager(Manager):
log.info("push from the %-8s %s:%s", "sandbox", image, tag)
yield from self.run_in_executor(docker_check_error, self.ctrl.sandbox.push, image, tag)
reset()
with ses.begin():
prev = ses.query(WebappVersion).filter_by(
webapp_id = version.webapp_id,
......@@ -1202,16 +1205,10 @@ class PushManager(Manager):
for key in "updated_at", "changelog", "published":
setattr(prev, key, getattr(version, key))
# TODO get rid of this 'replaced' state (and delete the record immediately)
# The 'replaced' state was introduced to avoid a race condition
# if multiple tasks are calling push() concurrently. If
# the version row is deleted, then the second call to push()).
# However this 'replaced' state does not need to be
# written to the db (because is only important for the
# running controller process). We could use another way
# of storing this state.
# mark this version as replaced
# TODO: purge this entry after some time
version.state = int(VersionState.replaced)
ses.add(version)
class ImageManager:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment