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

   ### 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-0.07 seconds into test execution during the first parallel test 
(`ReaderTest.MultipleChunksParallel`). See #49272.
   
   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 ThreadPool* 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?
   
   1. **Replace `thread_local` with native Win32 TLS API on MinGW** 
(`thread_pool.cc`): Uses `TlsAlloc`/`TlsGetValue`/`TlsSetValue` instead of 
`thread_local` on MinGW to bypass the buggy `__emutls` emulation. Non-MinGW 
platforms are unchanged.
   
   2. **Strengthen atomic memory ordering in `ThreadedTaskGroup`** 
(`task_group.cc`): Changed `nremaining_` operations from 
`memory_order_acquire`/`memory_order_release` to `memory_order_acq_rel` as 
defensive hardening. This is zero-cost on x86.
   
   3. **Add SEH crash handler for MinGW test builds** (`reader_test.cc`): Logs 
the exception code and address on crash, providing better debugging info if 
segfaults recur.
   
   4. **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` and 
`AsyncStreamingReaderTest.AsyncReentrancy` tests also cover the affected code 
paths.
   
   ### 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