Skip to content

Commit

Permalink
Merge pull request #13587 from manadart/2.9-raflease-client-test-race
Browse files Browse the repository at this point in the history
#13587

Fixes a testing race in `github.com/juju/juju/api/raftlease.(*RaftLeaseRemoteSuite).TestSetAddress()`.

See: https://jenkins.juju.canonical.com/job/Unit-RunUnitTests-race-amd64/1050

The logic copies a reference under lock protection and uses it outside of the lock. To fix this we copy the value into a new reference that does not need lock protection.

## QA steps

Run `RaftLeaseRemoteSuite.TestSetAddress` in a loop with the `-race` flag.

## Documentation changes

None.

## Bug reference

N/A
  • Loading branch information
jujubot committed Jan 5, 2022
2 parents 672fe14 + 471522c commit f793468
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions api/raftlease/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,8 @@ func (r *remote) loop() error {
func (r *remote) connect() bool {
stop := make(chan struct{})

var info *api.Info
r.mutex.Lock()
info = r.config.APIInfo
info := *r.config.APIInfo
r.stopConnecting = stop
r.mutex.Unlock()

Expand All @@ -621,7 +620,7 @@ func (r *remote) connect() bool {
_ = retry.Call(retry.CallArgs{
Func: func() error {
r.config.Logger.Debugf("open api to %v", address)
conn, err := api.Open(info, api.DialOpts{
conn, err := api.Open(&info, api.DialOpts{
DialAddressInterval: 50 * time.Millisecond,
Timeout: 10 * time.Minute,
RetryDelay: 2 * time.Second,
Expand Down

0 comments on commit f793468

Please sign in to comment.