Skip to content

[NativeAOT] Fix a stress crash in thread detach at process shutdown. - #73912

Merged
VSadov merged 2 commits into
dotnet:mainfrom
VSadov:tlsmon
Aug 14, 2022
Merged

VSadov merged 2 commits into
dotnet:mainfrom
VSadov:tlsmon

Conversation

@VSadov

@VSadov VSadov commented Aug 14, 2022 •

Copy link
Copy Markdown
Member

fixes: #73116

At shutdown we allow some threads to terminate without removing themselves from the thread list. Once a TLS of such thread is released, the thread list becomes corrupted, so whoever iterates the list now or later crashes.

Since we cannot be sure that every thread is promptly aware that we are shutting down, we cannot let threads to exit without removing themselves from the thread list first.

@ghost ghost assigned VSadov Aug 14, 2022
@VSadov
VSadov requested review from janvorli and jkotas August 14, 2022 04:18
@VSadov

VSadov commented Aug 14, 2022 •

Copy link
Copy Markdown
Member Author

This crash/assert is such a nuisance when running libraries tests as a stress test.
It may not show up for a while and then produce a bunch of core dumps.

return;
}

pDetachingThread->Detach();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are going to skip FixAllocContext here. Is it going to cause problems/asserts with GC accounting if the GC manages to sneak in before the process actually exits?

Would it be better to only skip Thread::Destroy, but keep Thread::Detach?

@VSadov VSadov Aug 14, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably only affect statistics like total alloc bytes if someone manages to query for that before the exit.
We may as well call Thread::Detach. It is not a lot of savings if we don't.

@VSadov

VSadov commented Aug 14, 2022

Copy link
Copy Markdown
Member Author

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines Bot Aug 14, 2022
@VSadov

VSadov commented Aug 14, 2022

Copy link
Copy Markdown
Member Author

the failure on arm64 is #13757

@VSadov

VSadov commented Aug 14, 2022

Copy link
Copy Markdown
Member Author

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[NativeAOT] Stress crash in ThreadStore::DetachCurrentThread

2 participants