From d3bf5db279641be8571dd338c8b60ddb27d70cb6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:11:42 +0000 Subject: [PATCH 1/5] Initial plan From e0d66ffd520a563d188ed1fd70b1c07be3492210 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:16:56 +0000 Subject: [PATCH 2/5] Investigating #123950: Add diagnostic checks for monotonic clock on Linux Cherry-picked from https://github.com/jkotas/runtime/commit/7518cabd115ad6a0097672eaa83f4c3707e8e807 This change adds compile-time diagnostics to ensure that on Linux platforms, the HAVE_CLOCK_MONOTONIC and HAVE_PTHREAD_CONDATTR_SETCLOCK flags are properly set. This helps investigate the root cause of Task.Delay freezing when the system time is adjusted backwards, which should be using monotonic clocks instead of real-time clocks. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- src/coreclr/pal/src/synchmgr/synchmanager.cpp | 14 +++++++++++++- src/native/libs/System.Native/pal_threading.c | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index b6c44754210805..42cb3053db6ea5 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -2699,7 +2699,19 @@ namespace CorUnix pthread_condattr_destroy(&attrs); goto IPrC_exit; } -#endif // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK +#else // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK +#ifdef __linux__ + #error not expected to be here on Linux + +#if !HAVE_CLOCK_MONOTONIC +#error HAVE_CLOCK_MONOTONIC missing +#endif +#if !HAVE_PTHREAD_CONDATTR_SETCLOCK +#error HAVE_PTHREAD_CONDATTR_SETCLOCK missing +#endif + +#endif +#endif iEagains = 0; Mutex_retry: diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index db6133d49df6b9..8b29061ae57899 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -85,7 +85,11 @@ LowLevelMonitor* SystemNative_LowLevelMonitor_Create(void) int condAttrDestroyError; condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes); assert(condAttrDestroyError == 0); + (void)condAttrDestroyError; // unused in release build #else +#ifdef __linux__ + #error not expected to be here on Linux +#endif error = pthread_cond_init(&monitor->Condition, NULL); #endif if (error != 0) From f00978731f28cc621644300de21c58de4a25d959 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:45:18 +0000 Subject: [PATCH 3/5] Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in The CMake configuration was successfully detecting HAVE_CLOCK_MONOTONIC support, but the config.h.in template was missing the #cmakedefine01 directive, causing the macro to be undefined in the generated config.h. This resulted in the runtime falling back to wall-clock time (CLOCK_REALTIME) instead of monotonic clocks, causing Task.Delay to freeze when the system time was adjusted backwards. This change adds the missing #cmakedefine01 HAVE_CLOCK_MONOTONIC line to src/coreclr/pal/src/config.h.in, ensuring the CMake-detected value is properly propagated to the C/C++ code. Applies https://github.com/jkotas/runtime/commit/224e4bdb99aaf7d50e555555a42d074c7af17330 Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- src/coreclr/pal/src/config.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/pal/src/config.h.in b/src/coreclr/pal/src/config.h.in index 49795de0a3dc41..a30f661035d1c4 100644 --- a/src/coreclr/pal/src/config.h.in +++ b/src/coreclr/pal/src/config.h.in @@ -87,6 +87,7 @@ #cmakedefine01 HAVE_WORKING_GETTIMEOFDAY #cmakedefine01 HAVE_WORKING_CLOCK_GETTIME #cmakedefine01 HAVE_CLOCK_THREAD_CPUTIME +#cmakedefine01 HAVE_CLOCK_MONOTONIC #cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK #cmakedefine01 MMAP_ANON_IGNORES_PROTECTION #cmakedefine01 ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS From b0a56d7216723765ef4270610946bd701a5d5fa5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 14:11:43 +0000 Subject: [PATCH 4/5] Add missing CMake feature definitions to config.h.in files Found and fixed additional missing #cmakedefine directives across multiple config.h.in files: 1. src/coreclr/pal/src/config.h.in: Added HAVE_STRERRORNAME_NP - Checked in configure.cmake line 144 - Used in src/coreclr/pal/src/misc/utils.cpp for friendly error messages 2. src/mono/cmake/config.h.in: Added HAVE_SYSSIGNAME - Checked in configure.cmake line 117 - Used in src/mono/mono/utils/mono-signal-handler.c for signal name lookup These were the same type of issue as HAVE_CLOCK_MONOTONIC - CMake was successfully detecting these features, but the configuration values were not being propagated to the generated config.h headers due to missing #cmakedefine directives. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- src/coreclr/pal/src/config.h.in | 1 + src/mono/cmake/config.h.in | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/coreclr/pal/src/config.h.in b/src/coreclr/pal/src/config.h.in index a30f661035d1c4..ac9f781d4c88f7 100644 --- a/src/coreclr/pal/src/config.h.in +++ b/src/coreclr/pal/src/config.h.in @@ -54,6 +54,7 @@ #cmakedefine01 HAS_PTHREAD_MUTEXES #cmakedefine HAVE_TTRACE #cmakedefine01 HAVE_PIPE2 +#cmakedefine01 HAVE_STRERRORNAME_NP #cmakedefine01 HAVE_SCHED_GETAFFINITY #cmakedefine01 HAVE_SCHED_SETAFFINITY #cmakedefine HAVE_UNW_GET_SAVE_LOC diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index b5224211265cdb..c5d79387848ccf 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -260,6 +260,9 @@ /* Define to 1 if you have the `sigaction' function. */ #cmakedefine HAVE_SIGACTION 1 +/* Define to 1 if you have the sys_signame array. */ +#cmakedefine HAVE_SYSSIGNAME 1 + /* CLOCK_MONOTONIC */ #cmakedefine HAVE_CLOCK_MONOTONIC 1 From eb756e2d159d5c942c9c7fa2c0a1a1767a4e1fac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 6 Feb 2026 15:09:55 +0000 Subject: [PATCH 5/5] Revert extra changes, keep only HAVE_CLOCK_MONOTONIC fix As requested, keeping only the one-line fix for HAVE_CLOCK_MONOTONIC in src/coreclr/pal/src/config.h.in and reverting all other changes: - Reverted diagnostic checks in synchmanager.cpp and pal_threading.c - Reverted HAVE_STRERRORNAME_NP addition - Reverted HAVE_SYSSIGNAME addition to mono config This PR now contains only the minimal fix for issue #123950. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com> --- src/coreclr/pal/src/config.h.in | 1 - src/coreclr/pal/src/synchmgr/synchmanager.cpp | 14 +------------- src/mono/cmake/config.h.in | 3 --- src/native/libs/System.Native/pal_threading.c | 4 ---- 4 files changed, 1 insertion(+), 21 deletions(-) diff --git a/src/coreclr/pal/src/config.h.in b/src/coreclr/pal/src/config.h.in index ac9f781d4c88f7..a30f661035d1c4 100644 --- a/src/coreclr/pal/src/config.h.in +++ b/src/coreclr/pal/src/config.h.in @@ -54,7 +54,6 @@ #cmakedefine01 HAS_PTHREAD_MUTEXES #cmakedefine HAVE_TTRACE #cmakedefine01 HAVE_PIPE2 -#cmakedefine01 HAVE_STRERRORNAME_NP #cmakedefine01 HAVE_SCHED_GETAFFINITY #cmakedefine01 HAVE_SCHED_SETAFFINITY #cmakedefine HAVE_UNW_GET_SAVE_LOC diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index 42cb3053db6ea5..b6c44754210805 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -2699,19 +2699,7 @@ namespace CorUnix pthread_condattr_destroy(&attrs); goto IPrC_exit; } -#else // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK -#ifdef __linux__ - #error not expected to be here on Linux - -#if !HAVE_CLOCK_MONOTONIC -#error HAVE_CLOCK_MONOTONIC missing -#endif -#if !HAVE_PTHREAD_CONDATTR_SETCLOCK -#error HAVE_PTHREAD_CONDATTR_SETCLOCK missing -#endif - -#endif -#endif +#endif // HAVE_CLOCK_MONOTONIC && HAVE_PTHREAD_CONDATTR_SETCLOCK iEagains = 0; Mutex_retry: diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index c5d79387848ccf..b5224211265cdb 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -260,9 +260,6 @@ /* Define to 1 if you have the `sigaction' function. */ #cmakedefine HAVE_SIGACTION 1 -/* Define to 1 if you have the sys_signame array. */ -#cmakedefine HAVE_SYSSIGNAME 1 - /* CLOCK_MONOTONIC */ #cmakedefine HAVE_CLOCK_MONOTONIC 1 diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 8b29061ae57899..db6133d49df6b9 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -85,11 +85,7 @@ LowLevelMonitor* SystemNative_LowLevelMonitor_Create(void) int condAttrDestroyError; condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes); assert(condAttrDestroyError == 0); - (void)condAttrDestroyError; // unused in release build #else -#ifdef __linux__ - #error not expected to be here on Linux -#endif error = pthread_cond_init(&monitor->Condition, NULL); #endif if (error != 0)