fix race detector checking failed about hook

This commit is contained in:
skyjiang 2023-08-22 17:09:42 +08:00
parent c3098d5f7e
commit a0e3d7e82f
1 changed files with 13 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
"sync"
"sync/atomic"
"time"
@ -40,6 +41,7 @@ type (
)
type hooksMixin struct {
mu sync.RWMutex
slice []Hook
initial hooks
current hooks
@ -116,6 +118,9 @@ func (hs *hooksMixin) AddHook(hook Hook) {
func (hs *hooksMixin) chain() {
hs.initial.setDefaults()
hs.mu.Lock()
defer hs.mu.Unlock()
hs.current.dial = hs.initial.dial
hs.current.process = hs.initial.process
hs.current.pipeline = hs.initial.pipeline
@ -165,18 +170,26 @@ func (hs *hooksMixin) withProcessPipelineHook(
}
func (hs *hooksMixin) dialHook(ctx context.Context, network, addr string) (net.Conn, error) {
hs.mu.RLock()
defer hs.mu.RUnlock()
return hs.current.dial(ctx, network, addr)
}
func (hs *hooksMixin) processHook(ctx context.Context, cmd Cmder) error {
hs.mu.RLock()
defer hs.mu.RUnlock()
return hs.current.process(ctx, cmd)
}
func (hs *hooksMixin) processPipelineHook(ctx context.Context, cmds []Cmder) error {
hs.mu.RLock()
defer hs.mu.RUnlock()
return hs.current.pipeline(ctx, cmds)
}
func (hs *hooksMixin) processTxPipelineHook(ctx context.Context, cmds []Cmder) error {
hs.mu.RLock()
defer hs.mu.RUnlock()
return hs.current.txPipeline(ctx, cmds)
}