Skip to content

fix(redis): consistent grain directory disposal + multiplexer ownership tests#10182

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:reubenbond/redis-multiplexer-ownership-followup
Jun 8, 2026
Merged

fix(redis): consistent grain directory disposal + multiplexer ownership tests#10182
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:reubenbond/redis-multiplexer-ownership-followup

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Jun 4, 2026

Copy link
Copy Markdown
Member

Follow-up to #10146 (already merged), addressing the remaining Copilot review feedback on that PR.

Problem

Two issues were raised on the merged Redis multiplexer-ownership change:

  1. RedisGrainDirectory.Dispose() / DisposeAsync() returned early when _redis was null (for example, if the directory was disposed before Initialize ran, or after a failed initialization). In that case _disposed was never set and _database remained null!, so a subsequent Lookup would throw a NullReferenceException instead of behaving as disposed.
  2. The new shared/owned multiplexer behavior had no targeted tests for the non-streaming Redis providers.

Solution

  • Set _disposed = true at the very start of both Dispose() and DisposeAsync(), before the early return, so the directory consistently behaves as disposed even when initialization never completed.
  • Add RedisMultiplexerOwnershipTests covering the grain storage, membership, reminder, and grain directory providers. Each verifies that a shared (IsShared: true) IConnectionMultiplexer is left alone while an exclusively-created one is disposed, exercising both synchronous Dispose() and asynchronous DisposeAsync(). Two additional Redis-free tests cover the dispose-before-initialize regression directly.
Microsoft Reviewers: Open in CodeFlow

ReubenBond and others added 2 commits June 4, 2026 15:11
Mark RedisGrainDirectory as disposed before the early return in Dispose/DisposeAsync so that disposing before (or without) Initialize leaves the instance in a disposed state instead of throwing NullReferenceException from later calls such as Lookup.

Add tests covering shared (not disposed) and exclusive (disposed) multiplexers for the grain storage, membership, reminder, and grain directory providers, exercising both synchronous and asynchronous disposal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…t tests

The dispose-before-initialize directory tests are not gated by CheckForRedis and never connect, but GetConfigurationOptions parsed the Redis connection string unconditionally, throwing ArgumentNullException in CI environments where no Redis is configured (for example, the Functional test job). Fall back to an empty ConfigurationOptions when no connection string is set.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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