title: Http Server Read-Write timeouts and Server Side Events
body: <p>I'm writing a test app with SSE, but my problem is that
  ReadTimeout and WriteTimeout are closing the clients connection every 10 Seconds and because of this the main page are losing data.</p>
  
  <p>How can I manage this Issue, serving SSE and webpages together without goroutines leak risk and SSE working done?</p>
  
  <p>Server:</p>
  
  <pre><code>server := &amp;http.Server{Addr: addr,
      ReadTimeout:  10 * time.Second,
      WriteTimeout: 10 * time.Second,
      Handler:      s.mainHandler(),
  }
  </code></pre>
  
  <p>Handler:</p>
  
  <pre><code>func sseHandler(w http.ResponseWriter, r *http.Requests) {
      f, ok := w.(http.Flusher)
      if !ok {
          http.Error(w, "Streaming not supported!", http.StatusInternalServerError)
          log.Println("Streaming not supported")
          return
      }
      messageChannel := make(chan string)
      hub.addClient &lt;- messageChannel
      notify := w.(http.CloseNotifier).CloseNotify()
  
      w.Header().Set("Content-Type", "text/event-stream")
      w.Header().Set("Cache-Control", "no-cache")
      w.Header().Set("Connection", "keep-alive")
      for i := 0; i &lt; 1440; {
          select {
          case msg := &lt;-messageChannel:
              jsonData, _ := json.Marshal(msg)
              str := string(jsonData)
              fmt.Fprintf(w, "data: {\"str\": %s, \"time\": \"%v\"}\n\n", str, time.Now())
              f.Flush()
  
          case &lt;-time.After(time.Second * 60):
              fmt.Fprintf(w, "data: {\"str\": \"No Data\"}\n\n")
  
              f.Flush()
              i++
  
          case &lt;-notify:
              f.Flush()
              i = 1440
              hub.removeClient &lt;- messageChannel
          }
      }
  }
  </code></pre>