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

Replace error atomic.Value with error atomic.Pointer[errs] #779

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var _ wire = (*pipe)(nil)

type pipe struct {
conn net.Conn
error atomic.Value
error atomic.Pointer[errs]
clhks atomic.Value // closed hook, invoked after the conn is closed
pshks atomic.Value // pubsub hook, registered by the SetPubSubHooks
queue queue
Expand Down Expand Up @@ -337,6 +337,9 @@ func (p *pipe) background() {
}

func (p *pipe) _exit(err error) {
if err != nil {
p.error.Store(&errs{error: err})
}
p.error.CompareAndSwap(nil, &errs{error: err})
atomic.CompareAndSwapInt32(&p.state, 1, 2) // stop accepting new requests
_ = p.conn.Close() // force both read & write goroutine to exit
Expand Down Expand Up @@ -1544,12 +1547,16 @@ func (p *pipe) DoMultiCache(ctx context.Context, multi ...CacheableTTL) *redisre
}

func (p *pipe) Error() error {
if err, ok := p.error.Load().(*errs); ok {
return err.error
}
return nil
errPtr := p.error.Load()
if errPtr == nil {
return nil
}
return errPtr.error
}




func (p *pipe) Close() {
p.error.CompareAndSwap(nil, errClosing)
block := atomic.AddInt32(&p.blcksig, 1)
Expand Down
Loading