]> Cypherpunks repositories - gostls13.git/commitdiff
net, net/http: don't trace UDP dials
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 12 May 2016 22:12:11 +0000 (22:12 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 13 May 2016 01:19:05 +0000 (01:19 +0000)
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>

src/internal/nettrace/nettrace.go
src/net/dial.go
src/net/http/transport_test.go

index 51a8b2cc5ae645fa8428308d217c9ff4dbf04369..0f85d727c605bd71c2452091f21cffa0664263fd 100644 (file)
@@ -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)
 }
index 256ef3806147c426c18a4e4cf3756bd293fff221..5985421b0661a9bab78924b8758a29c3007b5bd5 100644 (file)
@@ -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)
index bde052524cb8da01ecceed64ba0214d3a965ad7b..ab26de2e9526a4a9378eef41c7e9069f5153fce2 100644 (file)
@@ -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)
        }