vanshaj2023 opened a new pull request, #49462:
URL: https://github.com/apache/arrow/pull/49462

   ### Rationale for this change
   
   The `arrow-json-test` intermittently segfaults on AMD64 Windows MinGW CI 
(both CLANG64 and MINGW64 environments), causing false CI failures. The crash 
occurs at 0.03 seconds into test execution during 
`ReaderTest.MultipleChunksParallel`. See #49272.
   
   Example failing runs:
   - 
https://github.com/apache/arrow/actions/runs/21956381694/job/63422678894?pr=49262
   - 
https://github.com/apache/arrow/actions/runs/21981450495/job/63504813441?pr=49259
   
   The root cause is MinGW's `__emutls` implementation for C++ `thread_local`, 
which has known race conditions during thread creation. When 
`ThreadPool::LaunchWorkersUnlocked` creates a new worker thread, the thread 
immediately writes to the `thread_local` `current_thread_pool_` variable. If 
`__emutls` hasn't finished initializing TLS for the new thread, this 
dereferences an invalid pointer, causing a segfault.
   
   ### What changes are included in this PR?
   
   **Replace `thread_local` with native Win32 TLS API on MinGW 
(`thread_pool.cc`):** Uses `TlsAlloc`/`TlsGetValue`/`TlsSetValue` via Arrow's 
`windows_compatibility.h` instead of `thread_local` on MinGW to bypass the 
buggy `__emutls` emulation. Non-MinGW platforms are unchanged. Includes error 
handling for `TlsAlloc` failure.
   
   **Add `MultipleChunksParallelStress` test (`reader_test.cc`):** Runs 
parallel JSON reading 20 times to help expose intermittent threading races.
   
   ### Are these changes tested?
   
   Yes. A new stress test (`ReaderTest.MultipleChunksParallelStress`) is added 
that repeatedly exercises the parallel JSON reading path. The existing 
`ReaderTest.MultipleChunksParallel` test also covers the affected code path.
   
   ### Are there any user-facing changes?
   
   No.
   
   **This PR contains a "Critical Fix".** The changes fix a bug that causes a 
crash (segfault) in `arrow-json-test` on MinGW Windows CI due to a race 
condition in MinGW's `__emutls` thread-local storage emulation during thread 
pool worker creation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to