title: Golang broken pipe
body: <p>I have a code segment that is reading from a TCP connection and after the first few connections, the server is outputing broken pipe however no error is occurring in my go code. The server sending the messages is at its core the coda hale metrics library, more specifically the <a href="http://metrics.dropwizard.io/3.1.0/apidocs/com/codahale/metrics/graphite/PickledGraphite.html" rel="nofollow noreferrer">PickledGraphite</a> class.</p>
  <p>here is the Go code that is reading:</p>
  <pre><code>func handleConn(conn net.Conn, id int) {
      fmt.Println(&quot;handleConn&quot;)
      defer conn.Close()
      buf := make([]byte, 0, 10240)
      tmp := make([]byte, 256)
      fmt.Printf(&quot;%v Reading...\n&quot;, id)
      for {
          n, err := conn.Read(tmp)
          fmt.Printf(&quot;%v Read %v\n&quot;, id, n)
          if err != nil {
              fmt.Printf(&quot;%v Got err: %v\n&quot;, id, err)
              if err != io.EOF {
                  fmt.Printf(&quot;%v read error: %v\n&quot;, id, err)
              }
              buf = append(buf, tmp[:n]...)
              break
          }
          buf = append(buf, tmp[:n]...)
      }
      fmt.Printf(&quot;%v Done Reading\n&quot;, id)
      // Do stuff with buf
  }
  
  func main() {
      ln, err := net.Listen(&quot;tcp&quot;, &quot;:5555&quot;)
      if err != nil {
          fmt.Println(err)
          os.Exit(-1)
      }
      id := 1
      for {
          fmt.Println(&quot;getting connection\n&quot;)
          conn, err := ln.Accept()
          if err != nil {
              fmt.Println(err)
              break
          }
          conn.SetReadDeadline(time.Now().Add(20 * time.Second))
          fmt.Println(&quot;Got connection&quot;)
          go handleConn(conn, id)
          id = id + 1
          fmt.Println(&quot;sent handleConn\n&quot;)
      }
  }
  </code></pre>
  <p>My code is still running, I can still execute <code>nc</code> commands and see my code receive it, so I am not sure how I am losing the connection.
  If I remove the <code>conn.SetReadDeadline()</code> line then what happens is my code no longer receives a EOF after the first message.
  Thanks in advance</p>