<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--- FAIL: TestTransportHeadChunkedResponse (0.01s)
    transport_test.go:611: ip/ports differed between head requests: &quot;127.0.0.1:47607&quot; vs &quot;127.0.0.1:47608&quot;
FAIL
FAIL    net/http    12.768s"><pre class="notranslate"><code class="notranslate">--- FAIL: TestTransportHeadChunkedResponse (0.01s)
    transport_test.go:611: ip/ports differed between head requests: "127.0.0.1:47607" vs "127.0.0.1:47608"
FAIL
FAIL    net/http    12.768s
</code></pre></div>
<p dir="auto"><a href="http://build.golang.org/log/5f8b7215370338c03fbb75d43befedcbd95ed2c3" rel="nofollow">http://build.golang.org/log/5f8b7215370338c03fbb75d43befedcbd95ed2c3</a></p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/bradfitz/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/bradfitz">@bradfitz</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mikioh/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/mikioh">@mikioh</a></p>
<p dir="auto">Noticed at <a href="http://build.golang.org/log/c4295893036b8f63339f2fdcfa6a7f052edbdfa4" rel="nofollow">http://build.golang.org/log/c4295893036b8f63339f2fdcfa6a7f052edbdfa4</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="--- FAIL: TestTransportHeadChunkedResponse-4 (0.02s)
    transport_test.go:611: ip/ports differed between head requests: &quot;127.0.0.1:54643&quot; vs &quot;127.0.0.1:54644&quot;
FAIL
FAIL    net/http    10.889s"><pre class="notranslate"><code class="notranslate">--- FAIL: TestTransportHeadChunkedResponse-4 (0.02s)
    transport_test.go:611: ip/ports differed between head requests: "127.0.0.1:54643" vs "127.0.0.1:54644"
FAIL
FAIL    net/http    10.889s
</code></pre></div>
<p dir="auto">The test is simply:</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="        defer afterTest(t)
        ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
                if r.Method != &quot;HEAD&quot; {
                        panic(&quot;expected HEAD; got &quot; + r.Method)
                }
                w.Header().Set(&quot;Transfer-Encoding&quot;, &quot;chunked&quot;) // client should ignore                                                     
                w.Header().Set(&quot;x-client-ipport&quot;, r.RemoteAddr)
                w.WriteHeader(200)
        }))
        defer ts.Close()

        tr := &amp;Transport{DisableKeepAlives: false}
        c := &amp;Client{Transport: tr}

        res1, err := c.Head(ts.URL)
        if err != nil {
                t.Fatalf(&quot;request 1 error: %v&quot;, err)
        }
        res2, err := c.Head(ts.URL)
        if err != nil {
                t.Fatalf(&quot;request 2 error: %v&quot;, err)
        }
        if v1, v2 := res1.Header.Get(&quot;x-client-ipport&quot;), res2.Header.Get(&quot;x-client-ipport&quot;); v1 != v2 {
                t.Errorf(&quot;ip/ports differed between head requests: %q vs %q&quot;, v1, v2)
        }
}"><pre class="notranslate">        <span class="pl-k">defer</span> <span class="pl-en">afterTest</span>(<span class="pl-s1">t</span>)
        <span class="pl-s1">ts</span> <span class="pl-c1">:=</span> <span class="pl-s1">httptest</span>.<span class="pl-en">NewServer</span>(<span class="pl-en">HandlerFunc</span>(<span class="pl-k">func</span>(<span class="pl-s1">w</span> <span class="pl-smi">ResponseWriter</span>, <span class="pl-s1">r</span> <span class="pl-c1">*</span><span class="pl-smi">Request</span>) {
                <span class="pl-k">if</span> <span class="pl-s1">r</span>.<span class="pl-c1">Method</span> <span class="pl-c1">!=</span> <span class="pl-s">"HEAD"</span> {
                        <span class="pl-en">panic</span>(<span class="pl-s">"expected HEAD; got "</span> <span class="pl-c1">+</span> <span class="pl-s1">r</span>.<span class="pl-c1">Method</span>)
                }
                <span class="pl-s1">w</span>.<span class="pl-en">Header</span>().<span class="pl-en">Set</span>(<span class="pl-s">"Transfer-Encoding"</span>, <span class="pl-s">"chunked"</span>) <span class="pl-c">// client should ignore                                                     </span>
                <span class="pl-s1">w</span>.<span class="pl-en">Header</span>().<span class="pl-en">Set</span>(<span class="pl-s">"x-client-ipport"</span>, <span class="pl-s1">r</span>.<span class="pl-c1">RemoteAddr</span>)
                <span class="pl-s1">w</span>.<span class="pl-en">WriteHeader</span>(<span class="pl-c1">200</span>)
        }))
        <span class="pl-k">defer</span> <span class="pl-s1">ts</span>.<span class="pl-en">Close</span>()

        <span class="pl-s1">tr</span> <span class="pl-c1">:=</span> <span class="pl-c1">&amp;</span><span class="pl-smi">Transport</span>{<span class="pl-c1">DisableKeepAlives</span>: <span class="pl-c1">false</span>}
        <span class="pl-s1">c</span> <span class="pl-c1">:=</span> <span class="pl-c1">&amp;</span><span class="pl-smi">Client</span>{<span class="pl-c1">Transport</span>: <span class="pl-s1">tr</span>}

        <span class="pl-s1">res1</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">c</span>.<span class="pl-en">Head</span>(<span class="pl-s1">ts</span>.<span class="pl-c1">URL</span>)
        <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
                <span class="pl-s1">t</span>.<span class="pl-en">Fatalf</span>(<span class="pl-s">"request 1 error: %v"</span>, <span class="pl-s1">err</span>)
        }
        <span class="pl-s1">res2</span>, <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">c</span>.<span class="pl-en">Head</span>(<span class="pl-s1">ts</span>.<span class="pl-c1">URL</span>)
        <span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
                <span class="pl-s1">t</span>.<span class="pl-en">Fatalf</span>(<span class="pl-s">"request 2 error: %v"</span>, <span class="pl-s1">err</span>)
        }
        <span class="pl-k">if</span> <span class="pl-s1">v1</span>, <span class="pl-s1">v2</span> <span class="pl-c1">:=</span> <span class="pl-s1">res1</span>.<span class="pl-c1">Header</span>.<span class="pl-en">Get</span>(<span class="pl-s">"x-client-ipport"</span>), <span class="pl-s1">res2</span>.<span class="pl-c1">Header</span>.<span class="pl-en">Get</span>(<span class="pl-s">"x-client-ipport"</span>); <span class="pl-s1">v1</span> <span class="pl-c1">!=</span> <span class="pl-s1">v2</span> {
                <span class="pl-s1">t</span>.<span class="pl-en">Errorf</span>(<span class="pl-s">"ip/ports differed between head requests: %q vs %q"</span>, <span class="pl-s1">v1</span>, <span class="pl-s1">v2</span>)
        }
}</pre></div>
<p dir="auto">Perhaps the first Head returns but the second Head call starts before the background Transport goroutines get scheduled and register that the connection is idle.</p>