Skip to content

⚡ Replace Thread.Sleep with Task.Delay in SettingsService - #71

Merged
spelech merged 1 commit into
mainfrom
perf-async-settings-service
Sep 20, 2026
Merged

spelech merged 1 commit into
mainfrom
perf-async-settings-service

Conversation

@spelech

@spelech spelech commented Sep 20, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses failed Jules session \13362444024584746614.

💡 What

  • Replaced blocking \Thread.Sleep(50)\ calls in file I/O retry loops with non-blocking \�wait Task.Delay(50, cancellationToken).
  • Added \LoadSettingsAsync(CancellationToken cancellationToken = default)\ and \SaveSettingsAsync(AppSettings settings, CancellationToken cancellationToken = default)\ to \ISettingsService\ with default interface implementations for 100% backward compatibility with all existing callers and test mocks.
  • Replaced \lock (SettingsLock)\ with an asynchronous-safe \SemaphoreSlim\ in \SettingsService\ to allow proper non-blocking synchronization across both async and sync callers.
  • Updated /api/settings\ GET and POST endpoints in \EngineEndpoints.cs\ to utilize async settings operations.
  • Added comprehensive unit tests in \AppSettingsTests\ verifying async load/save roundtrip and cache sharing between sync and async calls.

🎯 Why

  • Blocking threads with \Thread.Sleep\ inside locks starves the ASP.NET Core thread pool during transient retry delays.
  • Asynchronous file I/O and \Task.Delay\ prevent thread pool exhaustion.

@spelech
spelech merged commit 2f3ce5b into main Sep 20, 2026
2 checks passed
@spelech
spelech deleted the perf-async-settings-service branch September 20, 2026 15:38
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.

1 participant