Opened 14 years ago
Last modified 12 years ago
#9418 closed defect
Creating instances of Component class is unsafe in multi-thread — at Initial Version
Reported by: | Jun Omae | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 1.0 |
Component: | general | Version: | 0.12dev |
Severity: | normal | Keywords: | core component threadsafe |
Cc: | leho@…, felix.schwarz@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
The fetch/store operations are not atomic for ComponentManager.components
in trac/core.py:115-121,161.
The operations are unsafe in multi-thread.
Trac 0.12rc1 and 0.11.7 have the problem.
Test code
#! /usr/bin/python import sys import time from threading import Thread, Event from trac import __version__ as VERSION from trac.core import Component, ComponentManager class MTComponent(Component): def __init__(self): pass class TestThread(Thread): def __init__(self, manager, event): Thread.__init__(self) self.manager = manager self.event = event def run(self): manager = self.manager self.event.wait() obj = MTComponent(manager) self.id = id(obj) def main(): print 'Python %s' % sys.version print 'Trac %s' % VERSION for i in range(0, 100): manager = ComponentManager() event = Event() event.clear() threads = [] for j in range(0, 64): thr = TestThread(manager, event) threads.append(thr) thr.start() sys.setcheckinterval(1) event.set() for thr in threads: thr.join() ids = set(thr.id for thr in threads) if len(ids) != 1: print '#%d: Unsafe in multi-thread - %r' % (i, ids) main()
Result
Python 2.4.3 (#1, Sep 3 2009, 15:37:12) [GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] Trac 0.12rc1 #12: Unsafe in multi-thread - set([-1211591892, -1211592340]) #13: Unsafe in multi-thread - set([-1211591796, -1211592116]) #14: Unsafe in multi-thread - set([-1211592180, -1211591700, -1211591732]) #20: Unsafe in multi-thread - set([-1211591348, -1211591732]) #42: Unsafe in multi-thread - set([-1211591188, -1211592308, -1211591156]) #46: Unsafe in multi-thread - set([-1211590932, -1211592052]) #52: Unsafe in multi-thread - set([-1211590548, -1211590516]) #57: Unsafe in multi-thread - set([-1211590196, -1211590964]) #60: Unsafe in multi-thread - set([-1211590004, -1211592116]) #70: Unsafe in multi-thread - set([-1211589300, -1211589684, -1211589332]) #73: Unsafe in multi-thread - set([-1211589140, -1211590868]) #76: Unsafe in multi-thread - set([-1211588948, -1211591220]) #83: Unsafe in multi-thread - set([-1211555700, -1211591860]) #84: Unsafe in multi-thread - set([-1211555764, -1211555636]) #86: Unsafe in multi-thread - set([-1211555508, -1211555700]) #96: Unsafe in multi-thread - set([-1211590548, -1211588820])
Note:
See TracTickets
for help on using tickets.