Changes between Initial Version and Version 1 of Ticket #36551
- Timestamp:
- Aug 14, 2025, 9:31:36 AM (6 weeks ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #36551
- Property Easy pickings unset
-
Ticket #36551 – Description
initial v1 6 6 7 7 django/db/backends/base/base.py, line ~608 8 **9 Problematic Code**10 8 9 **Problematic Code** 10 {{{ 11 11 thread_ident = _thread.get_ident() 12 12 tid = str(thread_ident).replace("-", "") … … 14 14 self.savepoint_state += 1 # Race condition here 15 15 sid = "s%s_x%d" % (tid, self.savepoint_state) 16 }}} 16 17 17 18 **Impact** … … 26 27 27 28 The race condition can be reproduced with this simple test: 28 29 {{{#!python 29 30 import threading, time 30 31 … … 43 44 44 45 print(f'Final: {counter} (should be 5)') 46 }}} 45 47 46 48 Expected output: Final: 5 … … 55 57 - Inventory overselling in high-traffic scenarios 56 58 57 **Proposed Fix 58 ** 59 **Proposed Fix ** 60 59 61 Wrap the increment operation in the existing _thread_sharing_lock: 60 62 {{{#!python 61 63 thread_ident = _thread.get_ident() 62 64 tid = str(thread_ident).replace("-", "") … … 65 67 self.savepoint_state += 1 66 68 sid = "s%s_x%d" % (tid, self.savepoint_state) 67 69 }}} 68 70 This solution: 69 71 - Uses Django's existing thread safety infrastructure