diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2008-08-04 07:33:37 +0000 |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-08-04 07:33:37 +0000 |
commit | d868be8805b7f5c4f0356eb01f6d8feab43cc9b3 (patch) | |
tree | 7a85f9173c432c9146ff2629eac9557edec6693b /Python/pystate.c | |
parent | e7829a5b1b75fdee4f9b7afebeceb98be2d3b0d7 (diff) | |
download | cpython-git-d868be8805b7f5c4f0356eb01f6d8feab43cc9b3.tar.gz |
Adds a sanity check to avoid a *very rare* infinite loop due to a corrupt tls
key list data structure in the thread startup path.
This change is a companion to r60148 which already successfully dealt with a
similar issue on thread shutdown.
In particular this loop has been observed happening from this call path:
#0 in find_key ()
#1 in PyThread_set_key_value ()
#2 in _PyGILState_NoteThreadState ()
#3 in PyThreadState_New ()
#4 in t_bootstrap ()
#5 in pthread_start_thread ()
I don't know how this happens but it does, *very* rarely. On more than
one hardware platform. I have not been able to reproduce it manually.
(A flaky mutex implementation on the system in question is one hypothesis).
As with r60148, the spinning we managed to observe in the wild was due to a
single list element pointing back upon itself.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 36b06d67af..da417c1032 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -253,6 +253,10 @@ tstate_delete_common(PyThreadState *tstate) "PyThreadState_Delete: invalid tstate"); if (*p == tstate) break; + /* Sanity check. These states should never happen but if + * they do we must abort. Otherwise we'll end up spinning in + * in a tight loop with the lock held. A similar check is done + * in thread.c find_key(). */ if (*p == prev_p) Py_FatalError( "PyThreadState_Delete: small circular list(!)" |