runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Task.Delay hangs indefinitely on Linux ARM32 when system clock is set backwards (.NET 10 regression)

Open cafenroy opened this issue 11 months ago • 8 comments

Description

Task.Delay hangs when system clock is set backwards (.NET 10 regression)

Description

Task.Delay() hangs when the system clock is set backwards on Linux ARM32. This is a regression from .NET 9.

Reproduction

  1. Run await Task.Delay(10000) on Linux ARM32
  2. While waiting, set the system clock backwards
  3. Expected: Delay completes in ~10 seconds
  4. Actual: Delay hangs forever

Regression

  • .NET 9: ✅ Works correctly
  • .NET 10.0.1: ❌ Hangs/extends when clock set backwards

Environment

Tested on two Raspberry Pi CM4S systems:

System 1 System 2
OS Buildroot 2024.02 Buildroot 2025.02.7
Kernel 5.10.92-v7l 6.6.78-v7l
glibc - 2.41
Arch armv7l (32-bit) armv7l (32-bit)
.NET 10.0.1 10.0.1
Result ❌ Hangs ❌ Hangs

## Impact

Affects embedded/IoT systems where clock may be adjusted (NTP sync, RTC drift, etc.). All timer-based APIs affected: `Task.Delay`, others ??.


### Reproduction Steps

## Reproduction

1. Run `await Task.Delay(10000)` on Linux ARM32
2. While waiting, set the system clock backwards
3. **Expected**: Delay completes in ~10 seconds
4. **Actual**: Delay hangs forever

### Expected behavior

3. **Expected**: Delay completes in ~10 seconds


### Actual behavior

4. **Actual**: Delay hangs forever

### Regression?

It works as expected with .Net 9.

### Known Workarounds

Revert to dotnet 9.

### Configuration

## Environment

Tested on two Raspberry Pi CM4S systems:

| | System 1 | System 2 |
|---|---|---|
| **OS** | Buildroot 2024.02 | Buildroot 2025.02.7 |
| **Kernel** | 5.10.92-v7l | 6.6.78-v7l |
| **glibc** | - | 2.41 |
| **Arch** | armv7l (32-bit) | armv7l (32-bit) |
| **.NET** | 10.0.1 | 10.0.1 |
| **Result** | ❌ Hangs | ❌ Hangs |

### Other information

_No response_

cafenroy avatar Dec 30 '25 16:12 cafenroy

namespace ConsoleApp9;

public static class Program
{ 
    public static async Task Main()
    {
        int index = 0;
        while (true)
        {
            index++;
            Console.WriteLine($"Iteration {index}");
            await Task.Delay(1000); // Hangs when system date is set back in time.
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net10.0\publish\linux-arm\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net10.0</TargetFramework>
    <RuntimeIdentifier>linux-arm</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>
</Project>

cafenroy avatar Dec 30 '25 17:12 cafenroy

  1. Have you been able to test this with any other Linux distros, or even Windows?
  2. Is this a completely indefinite hang, or is it "hangs until the clock catches up to the new time offset"? That is, if you set the clock back 5 minutes, does it wait for 5 minutes and 10 seconds, or does it never complete?

Clockwork-Muse avatar Dec 30 '25 21:12 Clockwork-Muse

  1. The bug do not happen on Linux x64 (Ubuntu)
  2. It hangs forever.

cafenroy avatar Jan 05 '26 13:01 cafenroy

Hello,

We have the same bug also on Linux arm64.

@Clockwork-Muse: In our tests, it "hangs until the clock catches up to the new time offset".

Downgrading our application back to .NET 9 fixes the issue also for us.

eschgi avatar Jan 21 '26 16:01 eschgi

We've also encountered this while developing a Linux-based medical device. We can reproduce this in a generic Ubuntu VM.

wjohnstonsolventum avatar Feb 03 '26 17:02 wjohnstonsolventum

I also have this issue in Manjaro x64 and on Yocto using a 6.11 ARM32 Kernel. I'm pretty sure the system thaws again when it reaches the original time point plus the sleep duration. Looks like the runtime is using a wall clock rather than a monotonic clock.

I encountered the same behaviour with every kind of wait: Thread.Sleep, PerodicTimer, System.Threading.Timer,... See related issue.

hlippke avatar Feb 03 '26 20:02 hlippke

Windows does not show this effect

hlippke avatar Feb 03 '26 20:02 hlippke

Duplicate of #123950 that has more context.

jkotas avatar Feb 06 '26 15:02 jkotas