Conversation
The key store multiplexer was created with AbortOnConnectFail at its default, so an unreachable Redis threw from ConfigureServices and the instance never started. Parse the connection string and turn the abort off, the same way the pub/sub multiplexer does; Data Protection logs the failed key ring read and retries on the next request.
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.
Type: bugfix
Issue
With
Redis:PersistKeysToRedison, an instance does not start while that Redis is unreachable.AddGrandDataProtectioncallsConnectionMultiplexer.Connect(PersistKeysToRedisUrl)withAbortOnConnectFailat its default (true), and the defaultPersistKeysToRedisUrlin appsettings has noabortConnect=false, soConfigureServicesthrows:A short Redis restart during a deploy or a pod reschedule therefore takes down every new instance, even though a running instance would ride it out.
Solution
Parse the connection string with
ConfigurationOptions.Parseand setAbortOnConnectFail = false, the same way the pub/sub multiplexer already does inStartupApplication.RegisterCache.Connectnow returns a multiplexer that keeps reconnecting in the background.What Data Protection does while the key ring cannot be read (from
KeyRingProviderin ASP.NET Core, confirmed by running it):Key ring failed to load during application startupand lets the app start.An error occurred while reading the key ringand throws, so those requests answer 500 after the Redis backlog timeout (syncTimeout, 5 s by default). Nothing is cached, so the next request tries again.So the instance starts and
/health/liveanswers, but pages that need Data Protection fail until Redis is back. That is the intended trade-off: readiness still does not probe Redis (see R11 in the resilience roadmap).Breaking changes
None. An explicit
abortConnect=trueinPersistKeysToRedisUrlis now overridden, as it already was forRedisPubSubConnectionString.Testing
dotnet test src/Tests/Grand.Web.Common.Tests --filter DataProtectionRedisTests:AddGrandDataProtectionno longer throws with an unreachable Redis (it failed withRedisConnectionExceptionbefore the fix).Redis__PersistKeysToRedis=true. Before: the process exits with the exception above. After:Application started,/health/livereturns 200,/returns 500 after ~5 s and the log showsAn error occurred while reading the key ring.docker run --rm -p 6379:6379 redis:7-alpine). Within a few seconds/responds normally without a restart, andredis-cli -n 1 KEYS *showsDataProtection-Keys.dotnet test GrandNode.slnxpasses (Aspire.ServiceDefaults.Testsfailed once in the parallel run and passed 3 out of 3 times on its own; it does not touch this code).