title: Turning off connection pool for Go http.Client
body: <p>For testing purposes I'm trying to create a <code>net/http.Client</code> in Go that has connection pooling disabled. What I'm trying to achieve is a new TCP connection is established to the address on every HTTP/1.x request.</p>
  
  <p>Currently I have:</p>
  
  <pre><code>        c = &amp;http.Client{
              Transport: &amp;http.Transport{
                  DialContext: (&amp;net.Dialer{
                      Timeout:   5 * time.Second,
                      KeepAlive: 5 * time.Second,
                  }).DialContext,
                  TLSHandshakeTimeout:   5 * time.Second,
                  ResponseHeaderTimeout: 5 * time.Second,
                  ExpectContinueTimeout: 1 * time.Second,
              },
          }
  </code></pre>
  
  <p>Any ideas how should I tweak this?</p>
  
  <p>I'm seeing that if I set <code>c.Transport.MaxIdleConns = 1</code> this could work, but I'm not exactly sure if this still allows 1 in-use + 1 idle (2 total) TCP connections:</p>
  
  <pre><code>    // MaxIdleConns controls the maximum number of idle (keep-alive)
      // connections across all hosts. Zero means no limit.
      MaxIdleConns int
  </code></pre>
  
  <p>Similarly, it seems like <code>c.Dialer.KeepAlive = -1</code> could do this, too: </p>
  
  <pre><code>    // KeepAlive specifies the keep-alive period for an active
      // network connection.
      // If zero, keep-alives are enabled if supported by the protocol
      // and operating system. Network protocols or operating systems
      // that do not support keep-alives ignore this field.
      // If negative, keep-alives are disabled.
  </code></pre>
  
  <p>but I'm not sure about the behavior for TCP connections + Keep-Alive + HTTP.</p>
  
  <p>Another approach is to try to kill idle TCP connections as soon as possible, so I set <code>c.Transport.IdleConnTimeout = 1*time.Nanosecond</code>.</p>
  
  <p>When I did this, my <code>Client.Do()</code> now occassionally returns error:</p>
  
  <pre><code>tls: use of closed connection
  </code></pre>
  
  <p>I'm suspecting this is a Go stdlib issue (perhaps a race) that it uses a connection that should've been taken out of a pool.</p>