[New-bugs-announce] [issue8757] Race condition when checking for set in set

Daniel Stutzbach report at bugs.python.org
Tue May 18 23:07:34 CEST 2010

New submission from Daniel Stutzbach <daniel at stutzbachenterprises.com>:

"some_set in some_set_of_sets" contains a race condition that can lead to odd behavior.  To perform the test, the set_contains() function in setobject.c creates a temporary frozenset object (t), swaps the bodies of some_set and t, checks if t is in some_set_of_sets, then swaps the bodies back.

Unfortunately, comparisons or hash functions may release the GIL, so the swapped bodies may be exposed on a different thread, i.e., "some_set in some_set_of_sets" may cause "some_set" to be empty on some other thread.

The same race condition exists in set_discard() and set_remove().

Attached is a short script that demonstrates the problem and could be easily converted to a unit test.

components: Interpreter Core
files: set-race.py
messages: 106007
nosy: stutzbach
priority: normal
severity: normal
status: open
title: Race condition when checking for set in set
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2
Added file: http://bugs.python.org/file17388/set-race.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list