Skip to content

Commit

Permalink
Merge DialHost must connect to the requested host (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-sucha committed Apr 25, 2023
2 parents 87a7661 + 65fb7cb commit 4aa6119
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ Neal Turett <neal.turett@datadoghq.com>
Doug Schaapveld <djschaap@gmail.com>
Steven Seidman <steven.seidman@datadoghq.com>
Wojciech Przytuła <wojciech.przytula@scylladb.com>
João Reis <joao.reis@datastax.com>
João Reis <joao.reis@datastax.com>
Lauro Ramos Venancio <lauro.venancio@incognia.com>
5 changes: 3 additions & 2 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func (hd *defaultHostDialer) DialHost(ctx context.Context, host *HostInfo) (*Dia
return nil, fmt.Errorf("host missing port: %v", port)
}

addr := host.HostnameAndPort()
conn, err := hd.dialer.DialContext(ctx, "tcp", addr)
connAddr := host.ConnectAddressAndPort()
conn, err := hd.dialer.DialContext(ctx, "tcp", connAddr)
if err != nil {
return nil, err
}
addr := host.HostnameAndPort()
return WrapTLS(ctx, conn, addr, hd.tlsConfig)
}

Expand Down
7 changes: 7 additions & 0 deletions host_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ func (h *HostInfo) HostnameAndPort() string {
return net.JoinHostPort(h.hostname, strconv.Itoa(h.port))
}

func (h *HostInfo) ConnectAddressAndPort() string {
h.mu.Lock()
defer h.mu.Unlock()
addr, _ := h.connectAddressLocked()
return net.JoinHostPort(addr.String(), strconv.Itoa(h.port))
}

func (h *HostInfo) String() string {
h.mu.RLock()
defer h.mu.RUnlock()
Expand Down

0 comments on commit 4aa6119

Please sign in to comment.