morningman opened a new pull request, #446:
URL: https://github.com/apache/doris-thirdparty/pull/446

   ### Background
   
   Apache Doris compiles ORC's C++ unit tests into its BE unit test binary
   (`doris_be_test`), where they run beside the Doris suites in one
   multi-threaded process.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: None
   PR Type: Test
   
   Problem Summary:
   
   `WriterTest.writeTimestampWithTimezone` turned each case's wall-clock string
   into seconds with `setenv("TZ", writerTimezone)`, `tzset()` and `mktime()`,
   and back with `setenv("TZ", readerTimezone)` and `localtime_r()`, then
   restored or removed `TZ`. Changing the environment is not safe while another
   thread reads it. In `doris_be_test` on macOS, brpc's bvar sampler thread runs
   `sysctl -n vm.loadavg` through `posix_spawn()` every second, which reads
   `environ`, and ASAN caught it reading the array that `setenv()` had just
   reallocated:
   
   ```
   ERROR: AddressSanitizer: heap-use-after-free ... READ of size 8 ... thread T1
     #0 PosixSpawnImpl ... #3 bvar::read_load_average ... #10 
bvar::detail::SamplerCollector::sampling_thread
   freed by thread T0 here:
     #0 realloc ...
   ```
   
   Each case now passes the UTC offsets of the writer's and the reader's zone at
   its wall-clock time, as the tz database gives them (what the old `isDst`
   hints stood for), and the test converts with `timegm()` and `gmtime_r()`,
   which do not read `TZ`. The check is unchanged: reading in the reader's zone
   must give back the wall-clock time that was written in the writer's zone.
   
   ### Details
   
   - **Frequency:** once across about ten full macOS runs of `doris_be_test`
     (ASAN). Not seen on Linux, where brpc reads `/proc/loadavg` instead of
     starting a process.
   - **Root cause:** the test changed the process environment while other
     threads could read it; `setenv()` is not thread-safe.
   - **Coverage:** unchanged: the same sixteen writer/reader zone pairs and
     times. The offsets come from the tz database, not from ORC's own timezone
     code, so the test still checks ORC against an independent source. The only
     ambiguous time (Los Angeles, 2012-11-04 01:59:59, which happened twice)
     keeps the daylight-time reading its `isDst` hint asked for.
   
   ### Testing
   
   - macOS arm64, clang 22.1.8, ASAN, inside Doris's `doris_be_test`:
     `OrcTest/WriterTest.*` passes.
   - The sixteen offsets were checked with Python's `zoneinfo`.
   - Not run: ORC's own CTest build, and Linux.
   
   ### Release note
   
   None
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Partially verified: ORC's own CTest build and Linux 
were not run
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: the change, the investigation and this description
   - Human review: None yet
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to