Skip to content

Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in#124086

Merged
jkotas merged 5 commits intomainfrom
copilot/investigate-dotnet-issue-123950
Feb 7, 2026
Merged

Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in#124086
jkotas merged 5 commits intomainfrom
copilot/investigate-dotnet-issue-123950

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Description

Fixes issue #123950 where Task.Delay freezes when system time jumps backwards on .NET 10 Linux - a regression from .NET 8 and 9.

The root cause was a missing #cmakedefine01 HAVE_CLOCK_MONOTONIC directive in src/coreclr/pal/src/config.h.in. While CMake was successfully detecting monotonic clock support, the configuration value was never propagated to the generated config.h header. This caused the runtime to fall back to wall-clock time (CLOCK_REALTIME) instead of monotonic clocks (CLOCK_MONOTONIC), making timing operations vulnerable to system time adjustments.

Changes

Fix applied:

  • src/coreclr/pal/src/config.h.in:
    • Added #cmakedefine01 HAVE_CLOCK_MONOTONIC - Enables monotonic clock support, fixing the Task.Delay freeze when system time is adjusted backwards

This is a minimal one-line change that ensures the CMake-detected monotonic clock support is properly propagated to the C/C++ code.

Impact

The runtime will correctly use monotonic clocks on Linux for synchronization primitives and timing operations, making them immune to system time adjustments. This resolves the Task.Delay freeze behavior and restores .NET 8/9 behavior.

Original fix commit: jkotas@224e4bd

Original prompt

Create PR against main branch to investigate #123950. The PR should start with cherry picking jkotas@7518cab to validate the root cause of the issue


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 6, 2026
…inux

Cherry-picked from jkotas@7518cab

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>
Copilot AI changed the title [WIP] Cherry pick commit for investigating dotnet issue #123950 Investigate #123950: Add compile-time diagnostics for monotonic clock configuration Feb 6, 2026
Copilot AI requested a review from jkotas February 6, 2026 13:20
@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

@copilot Apply jkotas@224e4bd to see whether it fixes the issue

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 jkotas@224e4bd

Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 6, 2026

@copilot Apply jkotas@224e4bd to see whether it fixes the issue

Applied in f009787. The missing #cmakedefine01 HAVE_CLOCK_MONOTONIC in config.h.in prevented the CMake-detected value from being propagated to the code, causing the fallback to wall-clock time instead of monotonic clocks.

Copilot AI changed the title Investigate #123950: Add compile-time diagnostics for monotonic clock configuration Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in Feb 6, 2026
@github-actions github-actions bot added area-PAL-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 6, 2026
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>
Copilot AI changed the title Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in Fix #123950: Add missing CMake feature definitions to config.h.in files Feb 6, 2026
Copilot AI requested a review from jkotas February 6, 2026 14:13
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>
Copilot AI changed the title Fix #123950: Add missing CMake feature definitions to config.h.in files Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in Feb 6, 2026
Copilot AI requested a review from jkotas February 6, 2026 15:11
@stephentoub stephentoub marked this pull request as ready for review February 6, 2026 16:15
Copilot AI review requested due to automatic review settings February 6, 2026 16:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a CoreCLR PAL build-configuration regression where CMake detected monotonic clock support, but the result was not propagated into the generated config.h, causing PAL timing code to fall back to CLOCK_REALTIME and making waits susceptible to backward system time jumps (issue #123950).

Changes:

  • Add #cmakedefine01 HAVE_CLOCK_MONOTONIC to src/coreclr/pal/src/config.h.in so the generated config.h reflects the CMake probe result.
  • Re-enables the CLOCK_MONOTONIC-based code paths guarded by HAVE_CLOCK_MONOTONIC (e.g., in SynchManager) when supported.

@tannergooding
Copy link
Member

Are we considering this one for backport since it can impact all wait calls and their accuracy?

@jkotas
Copy link
Member

jkotas commented Feb 6, 2026

Yes, I plan to submit backport request

@jkotas
Copy link
Member

jkotas commented Feb 7, 2026

/ba-g known issues

@jkotas jkotas merged commit 109ebb3 into main Feb 7, 2026
104 of 108 checks passed
@jkotas jkotas deleted the copilot/investigate-dotnet-issue-123950 branch February 7, 2026 01:36
@jkotas
Copy link
Member

jkotas commented Feb 7, 2026

/backport to release/10.0

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Started backporting to release/10.0 (link to workflow run)

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

@jkotas backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Creating an empty commit: Initial plan
Applying: Investigating #123950: Add diagnostic checks for monotonic clock on Linux
.git/rebase-apply/patch:19: trailing whitespace.
#if !HAVE_CLOCK_MONOTONIC 
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	src/coreclr/pal/src/synchmgr/synchmanager.cpp
M	src/native/libs/System.Native/pal_threading.c
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/pal/src/synchmgr/synchmanager.cpp
Auto-merging src/native/libs/System.Native/pal_threading.c
Applying: Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in
Applying: Add missing CMake feature definitions to config.h.in files
Applying: Revert extra changes, keep only HAVE_CLOCK_MONOTONIC fix
error: sha1 information is lacking or useless (src/coreclr/pal/src/config.h.in).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0005 Revert extra changes, keep only HAVE_CLOCK_MONOTONIC fix
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

jkotas added a commit that referenced this pull request Feb 7, 2026
Fixes issue #123950 where Task.Delay freezes when system time jumps
backwards on .NET 10 Linux - a regression from .NET 8 and 9.

The root cause was a missing `#cmakedefine01 HAVE_CLOCK_MONOTONIC`
directive in `src/coreclr/pal/src/config.h.in`. While CMake was
successfully detecting monotonic clock support, the configuration value
was never propagated to the generated config.h header. This caused the
runtime to fall back to wall-clock time (CLOCK_REALTIME) instead of
monotonic clocks (CLOCK_MONOTONIC), making timing operations vulnerable
to system time adjustments.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants