title: Creating an idle timeout in Go?
body: <p>I use CloudFlare for one of my high volume websites, and it sits in front of my stack. </p>
  
  <p>The thing is CloudFlare leaves idle connections open in addition to creating new ones, and it's not a setting I can change. </p>
  
  <p>When I have Varnish or Nginx sitting in front listening on port 80 they have out of the box configuration to hang up the idle connections. </p>
  
  <p>This is fine until I had to add a proxy written in Go to the front of my stack. It uses the <code>net/http</code> standard library. </p>
  
  <p>I'm not a Go wizard but based on what people are telling me there are only read and write timeout settings but not hanging up idle connections. </p>
  
  <p>Now my server will fill up with connections and die unless I set a set read and write timeouts, but the problem with this is my backend takes a long time sometimes and it's causing good requests to be cut off when they shouldn't. </p>
  
  <p>What is the proper way to handle idle connections with Go http? </p>
  
  <p><strong>Edit 1:</strong> To be more clear, I'm using <code>httputil.NewSingleHostReverseProxy</code> to construct a proxy, which exposes transport options but only for the upstream. The problems I am having are downstream, they need to be set on the <code>http.Server</code> object that uses the ReverseProxy as a handler. <code>http.Server</code> does not expose transport.</p>
  
  <p><strong>Edit 2:</strong> I would prefer an idle timeout to a read timeout, since the later would apply to an active uploader.</p>
  
  <p>Thanks</p>