Ticket #106 (defect)
Opened 4 years ago
Last modified 4 years ago
ThreadAwareClass is not exactly thread aware
Status: closed (fixed)
| Reported by: | rszefler | Assigned to: | rdelon |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | CherryPy code | Keywords: | |
| Cc: |
ThreadAwareClass has a severe bug due to the lack of critical section protection in method ThreadAwareClass.__setattr__:
def __setattr__(self, name, value):
id = thread.get_ident()
if not self.__dict__['threadMap'].has_key(id):
## lock __dict__['threadMap'] here!!!
self.__dict__['threadMap'][id] = {}
## unlock __dict__['threadMap'] here!!!
self.threadMap[id][name] = value
This bug should be considered critical IMHO: the class is used all over the cherry code and it can make server's threads crash unpredictably.
All in all, I recommend your switching to Python 2.4 standard threading.local().
BTW before someone starts whining that the code is collision resistant, please do consult any basic parallel programming text and/or threading.local's source.
Change History
02/10/05 04:08:04: Modified by Lawouach
02/13/05 08:24:27: Modified by rdelon
- status changed from new to closed.
- resolution set to fixed.
Fixed. Thanks for notifying us


Indeed you're right it's quite an important issue. I'm not sure switching to a specific Python 2.4 option is a good idea though as it would break CP2 independance regarding Python version (it's true though that we only support >= 2.3).