Announce the library name without demanding IDatabase - #542
Merged
Merged
Conversation
Auxiliary.ExecuteAsync unconditionally cast its IDatabaseAsync to IDatabase in order to send the one-time CLIENT SETINFO lib-name/lib-ver pair. A retry-wrapped database (SE.Redis 3.1.0 WithRetry) is async-only - RetryDatabase implements IDatabaseAsync but not IDatabase - so every async module command issued through one threw InvalidCastException before the command was sent, making the retry categories added in #540 unusable from the async API. The announcement never needed the sync interface: it only needed it to create a batch to group the two commands, which don't need grouping. It is now typed as IDatabaseAsync and dispatched fire-and-forget via an internal ClientSetInfoAsync overload that takes dispatch flags, so there is no cast, no batch, and no round-trip on the caller's first command. In the expected case - fire-and-forget completing synchronously - no state machine is entered on this path at all: the overload hands back a cached completed task, and the caller only awaits (to consume a fault) if a task somehow comes back not-yet-completed. A synchronous failure in the version probe can no longer fail the caller's command either; announcing who we are is best-effort. Renamed SetInfoInPipeline -> SetLibraryInfoOnce (internal): there is no longer a pipeline involved. Task.IsCompletedSuccessfully only exists on modern .NET, so netstandard2.0/net481 get it as an extension property polyfill rather than open-coding the Status test at each site. Audited the rest of the library for the same shape: this was the only unconditional cast to a sync SE.Redis interface; SearchCommandsAsync's cluster cursor path was already type-tested. Tests cover an async module command and the first-use announcement over db.WithRetry(...) - both fail with InvalidCastException before this change - plus the synchronous completion that the fire-and-forget dispatch relies on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(specifically: support WithRetry)
Note: takes SE.Redis 3.1.3
Auxiliary.ExecuteAsync unconditionally cast its IDatabaseAsync to IDatabase in order to send the one-time CLIENT SETINFO lib-name/lib-ver pair. A retry-wrapped database (SE.Redis 3.1.0 WithRetry) is async-only - RetryDatabase implements IDatabaseAsync but not IDatabase - so every async module command issued through one threw InvalidCastException before the command was sent, making the retry categories added in #540 unusable from the async API.
The announcement never needed the sync interface: it only needed it to create a batch to group the two commands, which don't need grouping. It is now typed as IDatabaseAsync and dispatched fire-and-forget via an internal ClientSetInfoAsync overload that takes dispatch flags, so there is no cast, no batch, and no round-trip on the caller's first command. In the expected case - fire-and-forget completing synchronously - no state machine is entered on this path at all: the overload hands back a cached completed task, and the caller only awaits (to consume a fault) if a task somehow comes back not-yet-completed. A synchronous failure in the version probe can no longer fail the caller's command either; announcing who we are is best-effort.
Renamed SetInfoInPipeline -> SetLibraryInfoOnce (internal): there is no longer a pipeline involved.
Task.IsCompletedSuccessfully only exists on modern .NET, so netstandard2.0/net481 get it as an extension property polyfill rather than open-coding the Status test at each site.
Audited the rest of the library for the same shape: this was the only unconditional cast to a sync SE.Redis interface; SearchCommandsAsync's cluster cursor path was already type-tested.
Tests cover an async module command and the first-use announcement over db.WithRetry(...) - both fail with InvalidCastException before this change - plus the synchronous completion that the fire-and-forget dispatch relies on.
Note
Medium Risk
Touches first-command behavior on every connection and transaction edge cases for library announcement; dependency bump to experimental WithRetry APIs affects all consumers.
Overview
Fixes async module commands on
db.WithRetry(...)by removing theIDatabasecast in the one-time CLIENT SETINFO announcement.SetLibraryInfoOnce(renamed fromSetInfoInPipeline) runs onIDatabaseAsync, sends lib-name/lib-ver as fire-and-forget (no batch, no extra round-trip on the caller’s first command), and skipsITransactionAsyncso SETINFO is not queued into MULTI/EXEC; announcement failures are best-effort.Adds an internal
ClientSetInfoAsync(..., CommandFlags)fast path for synchronous fire-and-forget completion, aTask.IsCompletedSuccessfullypolyfill for netstandard/net481, andWithRetryTestsfor retry DB/transactions and transaction announcement behavior.Dependency: StackExchange.Redis 3.0.25 → 3.1.3;
CommandCategoriesnow aliasesCommandFlags.CommandRetry*(drops int casts); SER007 suppressed repo-wide; test projects use central package version (no 3.1.0 override).Reviewed by Cursor Bugbot for commit 40f3a69. Bugbot is set up for automated code reviews on this repo. Configure here.