Skip to content

Commit

Permalink
tcp: fixed mu locking and unlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
susruth committed Sep 3, 2019
1 parent 984ab3c commit ad5a252
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tcp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ func (clientConns *ClientConns) Write(ctx context.Context, addr net.Addr, messag
return nil
}

// A new connection needs to be dialed, so we lock the connection to prevent
// multiple dials against the same remote server
conn.mu.Lock()
defer conn.mu.Unlock()

// Double-check the connection, because while waiting to acquire the write lock
// another goroutine may have already dialed the remote server
if conn.conn != nil {
Expand All @@ -164,6 +159,11 @@ func (clientConns *ClientConns) Write(ctx context.Context, addr net.Addr, messag
return nil
}

// A new connection needs to be dialed, so we lock the connection to prevent
// multiple dials against the same remote server
conn.mu.Lock()
defer conn.mu.Unlock()

// Dial
conn.conn, err = net.DialTimeout("tcp", addr.String(), clientConns.options.Timeout)
if err != nil {
Expand Down

0 comments on commit ad5a252

Please sign in to comment.