Skip to content

Commit b096009

Browse files
fix bug causing assertion failure because find_name_in_mro can release the type lock
1 parent cdf5643 commit b096009

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Objects/typeobject.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6194,7 +6194,9 @@ _PyType_LookupStackRefAndVersion(PyTypeObject *type, PyObject *name, _PyStackRef
61946194
version_tag = type->tp_version_tag;
61956195
}
61966196
res = find_name_in_mro(type, name, out);
6197-
if (res >= 0 && version_tag != 0) {
6197+
// find_name_in_mro can release the type lock and another thread can
6198+
// modify the type, so we need to check version tag again before caching the result.
6199+
if (res >= 0 && version_tag != 0 && version_tag == type->tp_version_tag) {
61986200
_PyTypeCache_Insert(type, name, PyStackRef_AsPyObjectBorrow(*out));
61996201
}
62006202
END_TYPE_LOCK();

0 commit comments

Comments
 (0)