bpo-39776: Lock ++interp->tstate_next_unique_id. (GH-18746) by skrah · Pull Request #18746 · python/cpython (original) (raw)

@vstinner Yes, it deserves a blurb. :)

@pitrou Yes, I printed tstate->id in the reproducer code and it had tons of duplicates. So

var->var_cached_tsid == ts->id &&

sometimes returned cached values that had already been deallocated by a previous thread
with a duplicate id.

With this fix there are no longer any duplicates and the test does not crash. If you review,
could you glance at https://bugs.python.org/file48930/threaded_crash.zip and verify that
it is actually correct embedding code (I think it is). :)

ASAN in release mode still complains about another invalid read in ceval.c, but I
think that is unrelated (it is also present in master).