Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 171e6eb

Browse files
committed
pyrefcnt: fix flaky build due to threads + fork
A partially initialized thread may have an entry in the interpreter without a corresponding entry in the biased-refcounting hashtable. See #50
1 parent 66ef0ef commit 171e6eb

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Python/pyrefcnt.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,15 @@ _Py_queue_destroy(PyThreadState *tstate)
133133

134134
PyThreadState *value = NULL;
135135
if (!_Py_HASHTABLE_POP(ht, tid, value)) {
136-
Py_FatalError("_Py_queue_destroy: missing thread object queue");
136+
// Py_FatalError("_Py_queue_destroy: missing thread object queue");
137+
// FIXME(sgross): just ignore for now. There's a race where a new thread
138+
// can be created and added to the interpreter's thread-list before it's
139+
// initialized in the threads start method. The thread only adds itself
140+
// to the refcnt hashtable later on. In between the two, another thread
141+
// may fork, which leaves the PyThreadState in the interpreter but without
142+
// the corresponding entry in this hashtable.
143+
pthread_rwlock_unlock(&interp->object_queues_lk);
144+
return;
137145
}
138146
assert(value == tstate);
139147

0 commit comments

Comments
 (0)