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

DialHost must connect to the requested host #1683

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,4 @@ Valerii Ponomarov <kiparis.kh@gmail.com>
Neal Turett <neal.turett@datadoghq.com>
Doug Schaapveld <djschaap@gmail.com>
Steven Seidman <steven.seidman@datadoghq.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