mirror of
https://github.com/golang/go
synced 2024-11-12 06:20:22 -07:00
net, net/http: don't trace UDP dials
The httptrace.ConnectStart and ConnectDone hooks are just about the post-DNS connection to the host. We were accidentally also firing on the UDP dials to DNS. Exclude those for now. We can add them back later as separate hooks if desired. (but they'd only work for pure Go DNS) This wasn't noticed earlier because I was developing on a Mac at the time, which always uses cgo for DNS. When running other tests on Linux, I started seeing UDP dials. Updates #12580 Change-Id: I2b2403f2483e227308fe008019f1100f6300250b Reviewed-on: https://go-review.googlesource.com/23069 Reviewed-by: Andrew Gerrand <adg@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
4cffe44e36
commit
15f2d0e452
@ -32,12 +32,14 @@ type Trace struct {
|
||||
// actually be for circular dependency reasons.
|
||||
DNSDone func(netIPs []interface{}, coalesced bool, err error)
|
||||
|
||||
// ConnectStart is called before a Dial. In the case of
|
||||
// DualStack (Happy Eyeballs) dialing, this may be called
|
||||
// multiple times, from multiple goroutines.
|
||||
// ConnectStart is called before a TCPAddr or UnixAddr
|
||||
// Dial. In the case of DualStack (Happy Eyeballs) dialing,
|
||||
// this may be called multiple times, from multiple
|
||||
// goroutines.
|
||||
ConnectStart func(network, addr string)
|
||||
|
||||
// ConnectStart is called after a Dial with the results. It
|
||||
// may also be called multiple times, like ConnectStart.
|
||||
// ConnectStart is called after a TCPAddr or UnixAddr Dial
|
||||
// with the results. It may also be called multiple times,
|
||||
// like ConnectStart.
|
||||
ConnectDone func(network, addr string, err error)
|
||||
}
|
||||
|
@ -472,11 +472,21 @@ func dialSerial(ctx context.Context, dp *dialParam, ras addrList) (Conn, error)
|
||||
return nil, firstErr
|
||||
}
|
||||
|
||||
// traceDialType reports whether ra is an address type for which
|
||||
// nettrace.Trace should trace.
|
||||
func traceDialType(ra Addr) bool {
|
||||
switch ra.(type) {
|
||||
case *TCPAddr, *UnixAddr:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// dialSingle attempts to establish and returns a single connection to
|
||||
// the destination address.
|
||||
func dialSingle(ctx context.Context, dp *dialParam, ra Addr) (c Conn, err error) {
|
||||
trace, _ := ctx.Value(nettrace.TraceKey{}).(*nettrace.Trace)
|
||||
if trace != nil {
|
||||
if trace != nil && traceDialType(ra) {
|
||||
raStr := ra.String()
|
||||
if trace.ConnectStart != nil {
|
||||
trace.ConnectStart(dp.network, raStr)
|
||||
|
@ -3292,6 +3292,7 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
|
||||
wantSub("Getting conn for dns-is-faked.golang:" + port)
|
||||
wantSub("DNS start: {Host:dns-is-faked.golang}")
|
||||
wantSub("DNS done: {Addrs:[{IP:" + ip + " Zone:}] Err:<nil> Coalesced:false}")
|
||||
wantSub("Connecting to tcp " + ts.Listener.Addr().String())
|
||||
wantSub("connected to tcp " + ts.Listener.Addr().String() + " = <nil>")
|
||||
wantSub("Reused:false WasIdle:false IdleTime:0s")
|
||||
wantSub("first response byte")
|
||||
@ -3299,6 +3300,9 @@ func testTransportEventTrace(t *testing.T, noHooks bool) {
|
||||
wantSub("WroteRequest: {Err:<nil>}")
|
||||
wantSub("Wait100Continue")
|
||||
wantSub("Got100Continue")
|
||||
if strings.Contains(got, " to udp ") {
|
||||
t.Errorf("should not see UDP (DNS) connections")
|
||||
}
|
||||
if t.Failed() {
|
||||
t.Errorf("Output:\n%s", got)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user