Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis: Renew the underlying connection if there is an exception #1004

Merged
merged 2 commits into from
Mar 10, 2022

Conversation

JorTurFer
Copy link
Contributor

@JorTurFer JorTurFer commented Mar 10, 2022

What this PR does / why we need it: This PR solves the reconnection problem in Redis with Sentinel arch after master node is missing

Which issue(s) this PR fixes: Fixes #1003

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature

@JorTurFer JorTurFer changed the title Redis: The underlying connection is not renew if there is an exception Redis: Renew the underlying connection if there is an exception Mar 10, 2022
@JorTurFer
Copy link
Contributor Author

@sungam3r PTAL

@JorTurFer JorTurFer marked this pull request as ready for review March 10, 2022 12:53
@@ -63,6 +63,7 @@ public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context
}
catch (Exception ex)
{
_connections.TryRemove(_redisConnectionString, out _);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt sbout TryGetValue/TryAdd pair above. See #903, #905 . Also note that ConnectionMultiplexer dictionary value implements IDisposable and should be disposed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the first part, sorry.
Would you like that, instead of using TryGetValue/TryAdd/TryRemove I update it to match the approach from the PR that you have posted?
Related with IDisposable you are right, I'll update my PR with that 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like that, instead of using TryGetValue/TryAdd/TryRemove I update it to match the approach from the PR that you have posted?

Yes. In fact that should be done in many places to get rid of race conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification ❤️
I'll update my PR with both changes

Copy link
Contributor Author

@JorTurFer JorTurFer Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm doing the change and I have faced with a problem using GetOrAdd, it hasn't got an async method. That pushes me to use something like this:

var connection = _connections.GetOrAdd(_redisConnectionString, async key =>
{
    return ConnectionMultiplexer.Connect(key);
}); 

My concern here is about doing sync calls inside the async context of the health check execution. Maybe I create a bigger problem with that than the original race condition with TryAdd/TryGet/TryRemove.
Any thoughts/suggestion @sungam3r ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let's keep as is for now.

@sungam3r sungam3r added the enhancement New feature or request label Mar 10, 2022
@sungam3r sungam3r merged commit 9223e6a into Xabaril:master Mar 10, 2022
@JorTurFer
Copy link
Contributor Author

Thanks for merging :)
One question, when will be next release? (no rush, just for knowing)

@carlosrecuero
Copy link
Collaborator

carlosrecuero commented Mar 10, 2022 via email

@JorTurFer
Copy link
Contributor Author

wow, so fast! Thanks a ton ❤️

@carlosrecuero
Copy link
Collaborator

Published on package 6.0.3

@JorTurFer
Copy link
Contributor Author

❤️ ❤️ ❤️ ❤️

@sungam3r sungam3r mentioned this pull request Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redis (Sentinel): The underlying connection is not renew if it's broken
3 participants