Race condition between lease creation and event thread

Bug #1704359 reported by Pierre Riteau
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Blazar
Fix Released
High
Pierre Riteau

Bug Description

If a lease is created to start immediately, there is a possible race condition between the lease creation function (create_lease() in blazar/manager/service.py) and the manager thread running lease events.

The race condition happens in the following fashion:

1. create_lease() calls db_api.lease_create(lease_values). The lease_values dict contains events values, which means both lease and associated events are created. However, associated reservations are not yet created at this stage.
2. The manager thread running events is triggered by its periodic timer. It finds that the start_lease event is ready to run and executes _basic_action(). Since there is no reservation yet, _basic_action() only
marks the event status as 'DONE'.
3. create_lease() finishes running by creating reservations associated with the lease.
4. Reservations stay in "pending" status forever because the start_lease event has already run.

Pierre Riteau (priteau)
Changed in blazar:
importance: Undecided → High
assignee: nobody → Pierre Riteau (priteau)
milestone: none → 0.3.0
description: updated
Pierre Riteau (priteau)
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to blazar (master)

Fix proposed to branch: master
Review: https://review.openstack.org/483884

Changed in blazar:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to blazar (master)

Reviewed: https://review.openstack.org/483884
Committed: https://git.openstack.org/cgit/openstack/blazar/commit/?id=030e9edbd98fefbe681abc2d0bec7c9a10b0806c
Submitter: Jenkins
Branch: master

commit 030e9edbd98fefbe681abc2d0bec7c9a10b0806c
Author: Pierre Riteau <email address hidden>
Date: Thu Jul 13 21:14:09 2017 +0100

    Fix race condition between lease creation and event thread

    If a lease is created to start immediately, there is a possible race
    condition between the lease creation function (create_lease() in
    blazar/manager/service.py) and the manager thread running lease events.

    The race condition happens in the following fashion:

    1. create_lease() calls db_api.lease_create(lease_values). The
    lease_values dict contains events values, which means both lease and
    associated events are created. However, associated reservations are not
    yet created at this stage.
    2. The manager thread running events is triggered by its periodic timer.
    It finds that the start_lease event is ready to run and executes
    _basic_action(). Since there is no reservation yet, _basic_action() only
    marks the event status as 'DONE'.
    3. create_lease() finishes running by creating reservations associated
    with the lease.
    4. Reservations stay in "pending" status forever because the start_lease
    event has already run.

    This is resolved by separating event creation in the database from the
    lease creation and moving it after reservation creation is done.

    Change-Id: Ia954461a682b4c5eef6dd5f3d5b779650ce404aa
    Closes-Bug: #1704359

Changed in blazar:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.