Skip to content

Caching.StackExchangeRedis: add "force reconnect" pattern - #45261

Merged
mgravell merged 18 commits into
mainfrom
marcg/forcereconnect
Jan 30, 2023
Merged

mgravell merged 18 commits into
mainfrom
marcg/forcereconnect

Conversation

@mgravell

@mgravell mgravell commented Nov 24, 2022 •

Copy link
Copy Markdown
Contributor

Caching.StackExchangeRedis: add "force reconnect" pattern

Adds the "force reconnect" pattern as described in azure cache best practices, with an implementation modified to retain the pre-existing custom connect logic

Tests forced locally (they're [Skip] in the source), and observed with redis-cli monitor to validate that key-prefix still valid.

Description

  1. add "force reconnect" pattern via OnRedisError, opt-in based on new UseForceReconnect option (defaults to false)
  2. avoid thread-race problems by having Connect[Async] return the cache, rather than relying on field
  3. avoid thread-race problems by only using a single ref field (cache), rather than cache+muxer; access muxer indirectly (it is only ever needed to shut down)
  4. use more efficient key-prefix path via RedisKey.Append
  5. use more efficient hash-fetch by pre-storing the hash-key arrays (removes need for RedisExtensions.cs)
  6. general code tidy; null-handling, defaults, etc (no semantic change)
  7. rev SE.Redis dependency to 2.6.90, which has significant connection stability improvements

Fixes #39082

2. avoid thread-race problems by having Connect[Async] *return* the cache, rather than relying on field
3. avoid thread-race problems by only using a single ref field (cache), rather than cache+muxer; access indirectly
4. use more efficient key-prefix path via RedisKey.Append
5. use more efficient hash-fetch by pre-storing the hash-key arrays (removes need for RedisExtensions.cs)
6. general code tidy; null-handling, defaults, etc (no semantic change)
@mgravell

mgravell commented Nov 24, 2022 •

Copy link
Copy Markdown
Contributor Author

@mgravell

mgravell commented Dec 1, 2022

Copy link
Copy Markdown
Contributor Author

PR nits resolved; good feedback and discussion, thanks

@sgtobin

sgtobin commented Dec 13, 2022

Copy link
Copy Markdown

When/How can I get this feature?

@mgravell
mgravell requested review from a team, dougbu and wtgodbe as code owners January 10, 2023 16:54
@davidfowl

Copy link
Copy Markdown
Member

@BrennanConroy should we add this to the SignalR backplane as well?

Also @ReubenBond should this be part of the redis clustering provider for orleans?

@NickCraver

Copy link
Copy Markdown
Member

For the other projects: if using the StackExchange.Redis client, we'd recommend upgrading to latest (2.6.x) and see if you actually hit any issues. If so, please ping ASAP and let's fix those in the core library. This entire feature shouldn't be needed any more - if there are some scenarios still tossing the connection (and anything buffered, which the base library would send upon connecting up to the timeout), let's figure that out and improve for all. The workaround is inherently a bit destructive compared to the base library, and should only be a last resort.

For context: most of the need for something like this was before working with the Azure Redis cache folks to understand scenarios previously unknown and handling everything we're aware of today. TL;DR: it's mostly outdated advice, and the defaults should be doing good things today on latest library bits.

@BrennanConroy

Copy link
Copy Markdown
Member

This entire feature shouldn't be needed any more

So why are we doing this PR then?

@mgravell
mgravell requested a review from halter73 January 11, 2023 12:11
sebastienros and others added 2 commits January 13, 2023 12:01
- fixup interface delta in test harness
- make an analyzer happy about a redundant lambda
@halter73

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mgravell

Copy link
Copy Markdown
Contributor Author

/azp run

@mgravell

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mgravell

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mgravell

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mgravell

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@mgravell
mgravell merged commit 9fbc7c6 into main Jan 30, 2023
@mgravell
mgravell deleted the marcg/forcereconnect branch January 30, 2023 11:49
@ghost ghost added this to the 8.0-preview1 milestone Jan 30, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AddStackExchangeRedisCache & ForceReconnect for Azure App Service Linux containers