File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -41,15 +41,15 @@ type (
4141)
4242
4343type  hooksMixin  struct  {
44- 	hooksMu  * sync.Mutex 
44+ 	hooksMu  * sync.RWMutex 
4545
4646	slice    []Hook 
4747	initial  hooks 
4848	current  hooks 
4949}
5050
5151func  (hs  * hooksMixin ) initHooks (hooks  hooks ) {
52- 	hs .hooksMu  =  new (sync.Mutex )
52+ 	hs .hooksMu  =  new (sync.RWMutex )
5353	hs .initial  =  hooks 
5454	hs .chain ()
5555}
@@ -151,7 +151,7 @@ func (hs *hooksMixin) clone() hooksMixin {
151151	clone  :=  * hs 
152152	l  :=  len (clone .slice )
153153	clone .slice  =  clone .slice [:l :l ]
154- 	clone .hooksMu  =  new (sync.Mutex )
154+ 	clone .hooksMu  =  new (sync.RWMutex )
155155	return  clone 
156156}
157157
@@ -176,7 +176,14 @@ func (hs *hooksMixin) withProcessPipelineHook(
176176}
177177
178178func  (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 )
180187}
181188
182189func  (hs  * hooksMixin ) processHook (ctx  context.Context , cmd  Cmder ) error  {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments