Fix rare corruption in StaticMeta::head_ list around fork
Summary: In a rare case, the current thread's would be inserted in the StaticMeta linked list twice, causing the list to be corrupted, leading to code spinning forever. After a fork, in the child, only the current thread survives, so all other threads must be forcefully removed from StaticMeta. We do that by clearing the list and re-adding the current thread, but we didn't check whether the current thread was already there. It is possible for the current thread to not be in the list if it never used any ThreadLocalPtr objects with the same tag. Now, when the thread in the child tries to use a ThreadLocalPtr with the same tag, it adds itself to the list (##if (prevCapacity == 0) meta.push_back(threadEntry)##), but it had already been added by the post-fork handler, boom. Fix by adding the necessary check in onForkChild. Test Plan: @durham's test case, also added new test for this Reviewed By: delong.j@fb.com FB internal diff: D1158672 @override-unit-failures
Showing
Please register or sign in to comment