Skip to content

fix: single thread hosts can hang - #1032

Merged
Tr00d merged 11 commits into
supabase:masterfrom
CW-KieranVelez:fix/single-thread-fixes
Dec 3, 2026
Merged

Tr00d merged 11 commits into
supabase:masterfrom
CW-KieranVelez:fix/single-thread-fixes

Conversation

@CW-KieranVelez

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix, plus a build change that keeps it fixed.

What is the current behavior?

On single-threaded hosts such as Unity WebGL, the SDK can hang.

  • ConfigureAwait(false) was missing. Many awaits in the shipped packages captured the caller's synchronization context.
    • A caller that blocks on .Result or .Wait() under a UI context can deadlock.
    • On Unity WebGL there is no thread pool. An await that captures Unity's context finishes later from Unity's queue. .NET then refuses to run the next ConfigureAwait(false) continuation inline and sends it to the pool, where it never runs. That is how SignInWithPassword froze on WebGL while SignUp worked (Gotrue Helpers.MakeRequestAsync<T>).
  • SemaphoreSlim resumes waiters on the thread pool. Gotrue's persistence gate used one, so a contended wait never returned on WebGL.
  • Nothing stopped the gap from coming back. The .NET analyzers are off by default for netstandard targets, so CA2007 never ran.

What is the new behavior?

  • Analyzer enforcement (Directory.Build.props, ShippedSdk.globalconfig)
    • CA2007 is now an error for shipped packages under packages/. Test projects and CapabilityMatrix are excluded.
    • The analyzers are switched on with AnalysisMode=None, so only rules with an explicit severity run.
    • CA1068 is set to none. All 14 existing hits are in public signatures, where moving the CancellationToken parameter is a breaking change. This can be revisited in a major version.
  • SerialGate (Gotrue)
    • New internal async mutex that hands over to the next waiter inline, on the releasing thread. It completes the waiter's task from Release (or from cancellation) with no synchronization context current. Waiters are served in order.
    • Gotrue.Client now uses it instead of SemaphoreSlim. App callbacks are started after the gate is released, so app code never runs under it.
    • Covered by new SerialGateTests.
  • ConfigureAwait(false) sweep
    • Added to every await in Functions, Gotrue, Postgrest, Realtime, Storage and Supabase.
    • No other behavior change.

Additional context

  • Public API is unchanged.

@CW-KieranVelez CW-KieranVelez changed the title fix/single thread fixes fix: single thread hosts can hang Dec 2, 2026
Tr00d and others added 6 commits December 3, 2026 10:47
Add the ConfigureAwait(false) that master's new awaits lack (CA2007), forward the
cancellation token to the session update and notification in the passkey, Web3 and
recovery-code sign-ins (CA2016), restore the ConfigureAwait(false) on
Realtime.ConnectAsync that the Realtime split removed, and format the Postgrest
files the PR touches.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A context that queues work and never runs it, and responses delivered from outside
the SDK, stand in for Unity WebGL: a call that captured the context or went through
the pool would never finish. Also cover the cancellable wait path of SerialGate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rename the private fields of CacheBackedRequest without the underscore prefix and the
internal TryLoadFromCache to TryLoadFromCacheAsync, and cover the state it reports.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Tr00d
Tr00d merged commit 18b0c51 into supabase:master Dec 3, 2026
10 of 11 checks passed
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.

2 participants