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

Fix Data Race in hooksMixin When Using MinIdleConns and AddHook #2814

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

RyoMiyashita
Copy link
Contributor

#2730

Overview

This PR addresses a critical data race issue discovered in hooksMixin when MinIdleConns is set to a value greater than 1, and client.AddHook is used concurrently.

Problem

The data race was identified during test, specifically in scenarios where MinIdleConns triggers the creation of idle connections in a separate goroutine, while client.AddHook modifies the hooks concurrently. This concurrent access and modification of hooks.dialer led to a data race.

Solution

To resolve this concurrency issue, the following modifications were made:

Introduced a sync.Mutex in the hooksMixin struct to ensure thread-safe operations.
Implemented locking and unlocking around critical sections in AddHook and dialHook methods to prevent concurrent read/write conflicts.
Adjusted the clone method in hooksMixin to handle the mutex correctly, avoiding the copying of mutex state.

I invite feedback and further review on these changes!

@RyoMiyashita
Copy link
Contributor Author

@ofekshenawa
I'm in a bit of a rush to get it merged – it's pretty critical for our current project. Any chance you could take a peek soon? Would really appreciate a speedy review if possible!

@ofekshenawa
Copy link
Collaborator

Hey @RyoMiyashita !
I totally get the urgency. Just finished reviewing the changes and everything looks solid. I’m going to merge this into master now.

@ofekshenawa ofekshenawa merged commit a109302 into redis:master Dec 10, 2023
9 checks passed
@RyoMiyashita
Copy link
Contributor Author

@ofekshenawa
Thanks for taking the time to review and merge this. Really appreciate it!

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.

2 participants