mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2026-10-25 15:46:41 +08:00
macOS libc guards its time zone state with a private pthread_rwlock (`lcl_rwlock` in Libc stdtime/FreeBSD/localtime.c), taken by strftime(_l), wcsftime(_l), strptime(_l), localtime(_r), ctime(_r), mktime, timelocal, time2posix, posix2time, tzset and tzsetwall. It is the psynch rwlock that loses wakeups when its waiters are interrupted by signals (FB24027930), and the macOS query profiler signals every registered thread. The pthread_rwlock shim from #112267 does not reach it, because libsystem_c binds to libpthread through the two-level namespace. Seen in Fast test (arm_darwin) on #117253: S3 request signing (Aws::Utils::DateTime::ToGmtString), EnabledQuota::Impl::throwQuotaExceed and ExternalLoader::LoadingDispatcher::calculateNextUpdateTime (holding the ExternalLoader mutex) all wait in strftime_l -> _st_tzset_basic with no holder. Define these 16 functions in the force-loaded darwin-compatibility archive. Each resolves the libc function with dlsym(RTLD_NEXT) and calls it under one recursive mutex, so at most one thread of the binary is inside libc's time zone code and none waits on its rwlock. errno is preserved across the mutex, because a contended Darwin mutex retries an interrupted __psynch_mutexwait / __psynch_mutexdrop and can leave EINTR behind on success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>