title: HTTP server HandleFunc loop on timeout?
body: <p>I am working on a Go app that has a web server. I was trying to add timeouts and encountered an issue. Here's a sample code I made to reproduce it because posting the actual code would be impossible:</p>
  
  <pre><code>package main
  
  import (
      "fmt"
      "html/template"
      "net/http"
      "time"
  )
  
  var layout *template.Template
  
  func main() {
      router := http.NewServeMux()
      server := &amp;http.Server{
          Addr:         ":8888",
          Handler:      router,
          ReadTimeout:  5 * time.Second,
          WriteTimeout: 1 * time.Second,
          IdleTimeout:  15 * time.Second,
      }
  
      router.HandleFunc("/", home)
  
      var err error
      layout, err = template.ParseFiles("./layout.html")
      if err != nil {
          fmt.Printf("Error1: %+v\n", err)
      }
  
      server.ListenAndServe()
  }
  
  func home(w http.ResponseWriter, r *http.Request) {
      fmt.Println("responding")
      err := layout.Execute(w, template.HTML(`World`))
      if err != nil {
          fmt.Printf("Error2: %+v\n", err)
      }
      time.Sleep(5 * time.Second)
  }
  </code></pre>
  
  <p><strong>layout.html:</strong> <code>Hello {{.}}!</code></p>
  
  <p>When I run it and visit 127.0.0.1:8888, the browser stays loading, and the <code>home()</code> which is triggering the timeout, starts over again and it does it 10 times before it stops and the browser shows a connection reset error.</p>
  
  <p>I was expecting that after a timeout, the func would end immediately, the connection be closed and the browser stop loading and show an error.</p>
  
  <p>How can I achieve this?</p>