This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JunyiXie
Recipients JunyiXie
Date 2021-03-09.03:54:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615262084.5.0.815014213556.issue43441@roundup.psfhosted.org>
In-reply-to
Content
type->tp_version_tag = next_version_tag++;
when sub interpreters parallel, next_version_tag++ is thread-unsafe. may cause different type has same tp_version_tag.

cause method cache bug in _PyType_Lookup
#define MCACHE_HASH_METHOD(type, name)                                  \
        MCACHE_HASH((type)->tp_version_tag,                     \
                    ((PyASCIIObject *)(name))->hash)

    if (MCACHE_CACHEABLE_NAME(name) &&
        _PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
        /* fast path */
        unsigned int h = MCACHE_HASH_METHOD(type, name);
        struct type_cache *cache = get_type_cache();
        struct type_cache_entry *entry = &cache->hashtable[h];
        if (entry->version == type->tp_version_tag && entry->name == name) {
#if MCACHE_STATS
            cache->hits++;
#endif
            return entry->value;
        }
    }



static int
assign_version_tag(struct type_cache *cache, PyTypeObject *type)
{
...
    type->tp_version_tag = next_version_tag++;
...
}
History
Date User Action Args
2021-03-09 03:54:44JunyiXiesetrecipients: + JunyiXie
2021-03-09 03:54:44JunyiXiesetmessageid: <1615262084.5.0.815014213556.issue43441@roundup.psfhosted.org>
2021-03-09 03:54:44JunyiXielinkissue43441 messages
2021-03-09 03:54:44JunyiXiecreate