Skip to content

Commit ddd0103

Browse files
committed
robustsession: fix: acquire (write) mutex when modifying idxOffset
1 parent df7ef2a commit ddd0103

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

robustsession/robustsession.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ func CopyNetworks() []*Network {
9898
// This type is only exported so that you can expose internal network state
9999
// for debugging via CopyNetworks().
100100
type Network struct {
101+
// mu covers all following fields.
102+
mu sync.Mutex
101103
servers []string
102104
idxOffset int
103-
mu sync.RWMutex
104105
backoff map[string]backoffState
105106
}
106107

@@ -180,8 +181,8 @@ func newNetwork(networkname string) (*Network, error) {
180181
// case back-off prevents us from connecting anywhere right now, the function
181182
// blocks until back-off is over. Returns error on context cancellation.
182183
func (n *Network) server(ctx context.Context, random bool) (string, error) {
183-
n.mu.RLock()
184-
defer n.mu.RUnlock()
184+
n.mu.Lock()
185+
defer n.mu.Unlock()
185186

186187
for {
187188
soonest := time.Duration(math.MaxInt64)

0 commit comments

Comments
 (0)