Skip to content

Avoid blocking SemaphoreSlim.Wait in BuildDatasyncOfflineOptions for browser-wasm - #575

Open
AtakanUk wants to merge 1 commit into
CommunityToolkit:mainfrom
AtakanUk:fix/574-offline-options-wasm-lock
Open

AtakanUk wants to merge 1 commit into
CommunityToolkit:mainfrom
AtakanUk:fix/574-offline-options-wasm-lock

Conversation

@AtakanUk

@AtakanUk AtakanUk commented Oct 4, 2026

Copy link
Copy Markdown

Fixes #574

Problem

On .NET 11 single-threaded browser-wasm, blocking SemaphoreSlim.Wait (marked [UnsupportedOSPlatform("browser")]) throws. OfflineDbContext.BuildDatasyncOfflineOptions() used DisposableLock.AcquireLock(), which calls Wait(). This broke offline PullAsync and push (via OperationsQueueManager's Lazy<OfflineOptions>).

Fix

Replace the SemaphoreSlim-based lock with a plain lock on a private object. No await happens inside the critical section, and Monitor is supported on single-threaded wasm. The _optionsLock.Dispose() call was removed accordingly.

Tests

  • BuildDatasyncOfflineOptions_ReturnsSameInstance
  • BuildDatasyncOfflineOptions_ConcurrentCalls_BuildOnce
  • Full client test suite: 1434 passed, 0 failed.

Notes (not addressed here)

A CA1416 scan with SupportedPlatform=browser also flags MD5.HashData (PullRequestBuilder), HttpClientHandler.AutomaticDecompression (HttpClientExtensions), the now test-only sync DisposableLock.AcquireLock, and the sync-over-async Task.Run(...).GetResult() in OperationsQueueManager.UpdateOperationsQueue. These could be follow-ups.

…browser-wasm (CommunityToolkit#574)

Use a Monitor lock for the synchronous lazy init, since SemaphoreSlim.Wait is unsupported on single-threaded browser-wasm. Adds regression tests.
@AtakanUk
AtakanUk force-pushed the fix/574-offline-options-wasm-lock branch from 0de9ed9 to 9d5764d Compare October 4, 2026 07:34
@AtakanUk

AtakanUk commented Oct 4, 2026

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

This branch has not been deployed

No deployments
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.

BuildDatasyncOfflineOptions throws PlatformNotSupportedException on .NET 11 Blazor WebAssembly

1 participant