Skip to content

Use TimeProvider in RedisFacade and build net48 on all platforms - #739

Merged
borland merged 2 commits into
mainfrom
orion/redisfacade-timeprovider
Nov 17, 2026
Merged

borland merged 2 commits into
mainfrom
orion/redisfacade-timeprovider

Conversation

@borland

@borland borland commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Claude: (reviewed by 👨 Orion; I didn't see the need to change anything, claude has done well here)

Summary

RedisFacade now takes a TimeProvider, so tests can control time in its retry logic.

This PR also lets Halibut.csproj build for net48 on macOS and Linux. That exposed two net48 problems with the new TimeProvider dependency, which are fixed here.

Changes

Use TimeProvider in RedisFacade

  • Add a Microsoft.Bcl.TimeProvider package reference. TimeProvider is built into net8+, and this package provides it for net48.
  • Both RedisFacade constructors now require a TimeProvider. This breaks the public API: callers must pass one, usually TimeProvider.System.
  • The ExecuteWithRetry loops now use timeProvider.GetTimestamp() / GetElapsedTime() instead of Stopwatch, and timeProvider.Delay(...) instead of Task.Delay(...).
  • SubscribeToChannel's retry delay goes through a new DelayWithoutException.Delay(TimeSpan, TimeProvider, CancellationToken) overload.
  • Tests: RedisFacadeBuilder accepts an optional TimeProvider, defaulting to TimeProvider.System. A comment in RedisFacadeFixture explains that these integration tests run against a live Redis and should use the real clock.

Build net48 on every OS

  • Halibut.csproj no longer limits itself to net10.0 on macOS and Linux. It always targets net48;net10.0. The .NET SDK fetches Microsoft.NETFramework.ReferenceAssemblies from NuGet, so net48 compiles without Windows or Mono. Running net48 tests still needs Windows.
  • The test and helper projects are unchanged and still build only net10.0 off Windows.

Fix net48 problems

  • Package downgrade (NU1605): on net48, Microsoft.Bcl.TimeProvider 11.0.0 needs Microsoft.Bcl.AsyncInterfaces 11.0.0 or later, but we pinned 7.0.0. Microsoft.Bcl.AsyncInterfaces is bumped to 11.0.0, the latest stable version. Anything that uses the Halibut package now needs AsyncInterfaces 11.0.0 or later.
  • Missing overload: Task.Delay(TimeSpan, TimeProvider, CancellationToken) only exists on net8+. The code calls the timeProvider.Delay(delay, token) extension method instead. The package provides it for both net48 and net10.0, so no #if is needed.

Testing

  • dotnet build source/Halibut/Halibut.csproj succeeds on macOS for both net48 and net10.0, with no warnings or errors.
  • dotnet build source/Halibut.Tests/Halibut.Tests.csproj succeeds for net10.0.
  • I haven't run the tests locally. The net48 tests need Windows CI.

🤖 Generated with Claude Code

@borland
borland requested a review from a team as a code owner November 17, 2026 22:03
Remove the macOS/Linux-only condition that limited Halibut.csproj to
net10.0. The SDK fetches the .NET Framework reference assemblies from
NuGet, so net48 builds without Windows or Mono.

Building net48 found two problems from adding Microsoft.Bcl.TimeProvider:
- TimeProvider 11.0.0 needs Microsoft.Bcl.AsyncInterfaces >= 11.0.0 on
  net48, but we pinned 7.0.0, so restore failed with NU1605. Bump
  AsyncInterfaces to 11.0.0.
- The Task.Delay(TimeSpan, TimeProvider, CancellationToken) overload only
  exists on net8+. Use the timeProvider.Delay(...) extension method,
  which the package provides for both net48 and net10.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@borland
borland force-pushed the orion/redisfacade-timeprovider branch from 0d73d3a to 056e55d Compare November 17, 2026 22:04
if (!willRetry) throw;
log?.Write(EventType.Diagnostic, $"Redis operation failed, retrying in {retryDelay.TotalSeconds}s: {ex.Message}");
await Task.Delay(retryDelay, combinedToken);
await timeProvider.Delay(retryDelay, combinedToken);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: If we only targeted net8 or net10, then the idiomatic way to do this is await Task.Delay(retryDelay, timeProvider, combinedToken). That's what we'd do in server.

However because we need to target net48, the Task.Delay overload which accepts a TimeProvider doesn't exist. Microsoft has an extension method for back compat, which we're using here instead.

FWIW the extension method is defined here: https://github.com/dotnet/runtime/blob/fea407997bf391030846ba0180b6c039f3b8c318/src/libraries/Microsoft.Bcl.TimeProvider/src/System/Threading/Tasks/TimeProviderTaskExtensions.cs#L49

You can see it takes a different path on net4x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Redis Halibut queue doesn't work under net48, we have the option to make it not work under net48. Or remove the RedisFacade entirely from net48

@borland
borland enabled auto-merge November 17, 2026 22:15
@borland
borland merged commit f4ec0d3 into main Nov 17, 2026
13 checks passed
@borland
borland deleted the orion/redisfacade-timeprovider branch November 17, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants