title: rejected tcp connection does not return error
body: <p>I did some experiment on Golang net package.</p>
  
  <p>When I use a client to connect a server (without close connections), I found that server had error like this:
  "too many open files"
  It makes sense because the file open limit set in my os.</p>
  
  <p>However, I found that <strong>client never returned errors when connecting to server</strong>, which is weird since server had already rejected some of connection requests.</p>
  
  <pre><code>// Server code
  package main
  
  import (
      "log"
      "net"
  )
  
  func main() {
      listener, err := net.Listen("tcp", "localhost:7070")
      if err != nil {
          log.Fatalln(err)
      }
      for {
          conn, err := listener.Accept()
          if err != nil {
              log.Println(err, conn)
              continue
          }
      }
  }
  
  
  // Client code
  package main
  
  import (
      "log"
      "net"
  )
  
  func main() {
      cnt := 0
      for {
          conn, err := net.Dial("tcp", "localhost:7070")
          if err != nil {
              log.Println("!", conn.RemoteAddr())
              continue
          }
          cnt++
          n, err := conn.Write([]byte("hello"))
          if err != nil {
              log.Fatalln(err)
          }
  
          log.Println(cnt, n)
  
      }
  
  }
  </code></pre>
  
  <p>Can anyone tell me what happens here?</p>
  
  <p>thx.</p>