title: Strange behaviour of golang UDP server
body: <p>I wrote a simple UDP server in go. </p>
  
  <p>When I do <code>go run udp.go</code> it prints all packages I send to it. But when running <code>go run udp.go &gt; out</code> it stops passing <code>stdout</code> to the <code>out</code> file when the client stops.</p>
  
  <p>The client is simple program that sends 10k requests. So in the file I have around 50% of sent packages. When I run the client again, the <code>out</code> file grows again until the client script finishes.</p>
  
  <p>Server code:</p>
  
  <pre><code>package main
  
  import (
    "net"
  
    "fmt"
  )
  
  func main() {
    addr, _ := net.ResolveUDPAddr("udp", ":2000")
    sock, _ := net.ListenUDP("udp", addr)
  
    i := 0
    for {
      i++
      buf := make([]byte, 1024)
      rlen, _, err := sock.ReadFromUDP(buf)
      if err != nil {
        fmt.Println(err)
      }
      fmt.Println(string(buf[0:rlen]))
      fmt.Println(i)
      //go handlePacket(buf, rlen)
    }
  }
  </code></pre>
  
  <p>And here is the client code:</p>
  
  <pre><code>package main
  
  import (
    "net"
  
    "fmt"
  )
  
  func main() {
  
    num := 0
    for i := 0; i &lt; 100; i++ {
      for j := 0; j &lt; 100; j++ {
        num++
        con, _ := net.Dial("udp", "127.0.0.1:2000")
        fmt.Println(num)
        buf := []byte("bla bla bla I am the packet")
        _, err := con.Write(buf)
        if err != nil {
          fmt.Println(err)
        }
      }
    }
  }
  </code></pre>