Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

#8043 closed defect (fixed)

ticket fields may be generated more than once

Reported by: Stephen Compall <stephen.compall@…> Owned by: Christian Boos
Priority: normal Milestone: 0.11.3
Component: ticket system Version: 0.11.2.1
Severity: minor Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

In this definition of get_ticket_fields:

def get_ticket_fields(self):
    """Returns the list of fields available for tickets."""
    # This is now cached - as it makes quite a number of things faster,
    # e.g. #6436
    if self._fields is None:
        self._fields_lock.acquire()
        try:
            self._fields = self._get_ticket_fields()
        finally:
            self._fields_lock.release()
    return [f.copy() for f in self._fields]

there is a race condition. Obviously it is difficult to test, but may be easily imagined by simply imagining two threads trying to execute the body of get_ticket_fields at exactly the same time.

  1. Both threads test self._fields, discovering it is None, and entering the body of the if.
  2. Both threads attempt to acquire the lock. Thread Jabba gets it first.
  3. Jabba enters the try, calls _get_ticket_fields, the slow computation, and saves it.
  4. Jabba releases the lock, so Thread Solo gets it.
  5. Solo enters the try, calls _get_ticket_fields, the slow computation, and saves it.
  6. And so on…

self._fields must be rechecked after acquiring the lock to avoid this race condition.

Attachments (1)

8043-fix-race-ticket-fields-cache.patch (1.8 KB ) - added by Christian Boos 16 years ago.
Patch fixing the race condition, applies on r7853 0.11-stable branch

Download all attachments as: .zip

Change History (3)

comment:1 by Christian Boos, 16 years ago

Component: generalticket system
Milestone: 0.11.3
Owner: set to Christian Boos

Agreed, except for the point 6, as this race happens at most once (until the self._fields gets eventually cleared again).

It's nevertheless better to fix this, of course.

by Christian Boos, 16 years ago

Patch fixing the race condition, applies on r7853 0.11-stable branch

comment:2 by Christian Boos, 16 years ago

Resolution: fixed
Status: newclosed

Above patch applied in r7865. Thanks for noticing this issue and keep up the good work, it's much appreciated!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.