ThreadTransactionManager is unsafe in the presence of short-lived threads
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Launchpad itself |
Invalid
|
Undecided
|
James Henstridge | ||
ZODB |
Won't Fix
|
Medium
|
Unassigned | ||
transaction |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
The ThreadTransacti
The thread.get_ident() function returns an identifier for the current thread that is unique during the lifetime of the thread. This works okay for long running threads, but causes problems if transactions are used within short running threads. The value of thread.get_ident() can (and does) get reused by threads that are created one after the other.
On my system (Linux with glibc-2.7), the following test program prints the same thread ID 10 times:
import thread
import threading
def foo():
print 'Thread ID:', thread.get_ident()
for i in range(10):
t = threading.
t.start()
t.join()
If these threads had been using the transaction module, they'd have all shared the same transaction. This is causes problems if a previous thread had exited uncleanly and the new thread starts part way through the existing transaction.
Using a threading.local() object to store the per-thread transaction would fix this problem.
Changed in zodb: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
tags: | added: tech-debt |
Changed in zodb: | |
status: | Fix Committed → Fix Released |
Changed in transaction: | |
status: | New → Fix Released |
Changed in zodb: | |
status: | Fix Released → Won't Fix |
Hey James,
I remember when you found this bug, but I don't remember how it affects launchpad-bazaar. Is this still an issue for us?
jml