Bug 773124

Summary: race condition when adding distros
Product: [Retired] Beaker Reporter: Dan Callaghan <dcallagh>
Component: lab controllerAssignee: Dan Callaghan <dcallagh>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: low    
Version: 0.8CC: bpeck, dcallagh, mcsontos, rmancy, stl
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 752869 Environment:
Last Closed: 2012-04-26 07:16:32 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On: 752869    
Bug Blocks:    

Description Dan Callaghan 2012-01-11 01:00:16 UTC
+++ This bug was initially created as a clone of Bug #752869 +++

Description of problem:
If two lab controllers try to add the same new distro at the same time only one of them will succeed.

Comment 1 Dan Callaghan 2012-01-11 01:03:08 UTC
Bug 752869 was fixed in Beaker 0.8 with a workaround: the call to add a new distro was split into two separate calls, and the first (subject to the race) was permitted to fail.

The proper fix for this bug is to use MappedObject.lazy_create, and to make that method be race-free using nested transactions.

    session.begin_nested()
    try:
        item = cls(**kwargs)
        session.commit()
    except IntegrityError:
        session.rollback()
        item = cls.query.filter_by(**kwargs).one()