File tree 1 file changed +11
-4
lines changed 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -41,15 +41,15 @@ type (
41
41
)
42
42
43
43
type hooksMixin struct {
44
- hooksMu * sync.Mutex
44
+ hooksMu * sync.RWMutex
45
45
46
46
slice []Hook
47
47
initial hooks
48
48
current hooks
49
49
}
50
50
51
51
func (hs * hooksMixin ) initHooks (hooks hooks ) {
52
- hs .hooksMu = new (sync.Mutex )
52
+ hs .hooksMu = new (sync.RWMutex )
53
53
hs .initial = hooks
54
54
hs .chain ()
55
55
}
@@ -151,7 +151,7 @@ func (hs *hooksMixin) clone() hooksMixin {
151
151
clone := * hs
152
152
l := len (clone .slice )
153
153
clone .slice = clone .slice [:l :l ]
154
- clone .hooksMu = new (sync.Mutex )
154
+ clone .hooksMu = new (sync.RWMutex )
155
155
return clone
156
156
}
157
157
@@ -176,7 +176,14 @@ func (hs *hooksMixin) withProcessPipelineHook(
176
176
}
177
177
178
178
func (hs * hooksMixin ) dialHook (ctx context.Context , network , addr string ) (net.Conn , error ) {
179
- return hs .current .dial (ctx , network , addr )
179
+ // Access to hs.current is guarded by a read-only lock since it may be mutated by AddHook(...)
180
+ // while this dialer is concurrently accessed by the background connection pool population
181
+ // routine when MinIdleConns > 0.
182
+ hs .hooksMu .RLock ()
183
+ current := hs .current
184
+ hs .hooksMu .RUnlock ()
185
+
186
+ return current .dial (ctx , network , addr )
180
187
}
181
188
182
189
func (hs * hooksMixin ) processHook (ctx context.Context , cmd Cmder ) error {
You can’t perform that action at this time.
0 commit comments