Closed RyoMiyashita closed 9 months ago
@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!
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 Thanks for taking the time to review and merge this. Really appreciate it!
2730
Overview
This PR addresses a critical data race issue discovered in
hooksMixin
whenMinIdleConns
is set to a value greater than 1, andclient.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, whileclient.AddHook
modifies the hooks concurrently. This concurrent access and modification ofhooks.dialer
led to a data race.Solution
To resolve this concurrency issue, the following modifications were made:
Introduced a
sync.Mutex
in thehooksMixin
struct to ensure thread-safe operations. Implemented locking and unlocking around critical sections inAddHook
anddialHook
methods to prevent concurrent read/write conflicts. Adjusted the clone method inhooksMixin
to handle the mutex correctly, avoiding the copying of mutex state.I invite feedback and further review on these changes!