Opened 16 years ago
Closed 16 years ago
#8043 closed defect (fixed)
ticket fields may be generated more than once
Reported by: | 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.
- Both threads test
self._fields
, discovering it isNone
, and entering the body of theif
. - Both threads attempt to acquire the lock. Thread Jabba gets it first.
- Jabba enters the
try
, calls_get_ticket_fields
, the slow computation, and saves it. - Jabba releases the lock, so Thread Solo gets it.
- Solo enters the
try
, calls_get_ticket_fields
, the slow computation, and saves it. - And so on…
self._fields
must be rechecked after acquiring the lock to avoid this race condition.
Attachments (1)
Change History (3)
comment:1 by , 16 years ago
Component: | general → ticket system |
---|---|
Milestone: | → 0.11.3 |
Owner: | set to |
by , 16 years ago
Attachment: | 8043-fix-race-ticket-fields-cache.patch added |
---|
Patch fixing the race condition, applies on r7853 0.11-stable branch
comment:2 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Above patch applied in r7865. Thanks for noticing this issue and keep up the good work, it's much appreciated!
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.