[2019-08] [threads] clear small_id_key TLS when unregistering a thread #17015
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes
Debugged by @lambdageek. Contributes to #10641
Edit: C/p into PR description so it's in the commit message:
We think what happens is:
start_wrapperrunsunregister_threadwhen the thread is exiting. At that point thesmall_idfor the thread is cleared from the hazard pointer bitset bymono_thread_small_id_free (small_id)Some other TLS destructor runs and attaches the thread again (which runs
mono_thread_info_register_small_idwhich first callsmono_thread_info_get_small_idwhich tries to get the small id from thesmall_id_keyTLS key and so the newMonoThreadInfohas the samesmall_idas the previously destroyedMonoThreadInfo- but the hazard pointer bitset is not updated).This other TLS destructor runs and calls
mono_thread_detach_if_exitingwhich callsunregister_threadagain.unregister_threadcallsmono_thread_small_id_free (small_id)a second time which asserts because we already cleared that id from the hazard pointer bitset.Backport of #16973.
/cc @lewurm