title: TCPConn SetWriteDeadline not working
body: <p>I'm writing a TCP client in <strong>Golang</strong>. The server will never send any replies, or any data.</p>
  
  <p>As soon as I fail to write after a given timeout I want the client to close the connection.</p>
  
  <p>So from reading the documentation for <code>SetWriteDeadline</code> in <code>Conn</code>:
  <a href="https://golang.org/pkg/net/#Conn" rel="nofollow noreferrer">https://golang.org/pkg/net/#Conn</a></p>
  
  <pre><code>    // SetWriteDeadline sets the deadline for future Write calls
      // and any currently-blocked Write call.
      // Even if write times out, it may return n &gt; 0, indicating that
      // some of the data was successfully written.
      // A zero value for t means Write will not time out.
      SetWriteDeadline(t time.Time) error
  </code></pre>
  
  <p>From the above description I use it like this:</p>
  
  <pre><code>...
  for {
      select {
      case msg := &lt;-messages:
          conn.SetWriteDeadline(time.Now().Add(1 * time.Second))
  
          // When server goes away this just blocks forever. No timeout!
          n, err := conn.Write(msg.ByteArray())
          if err != nil {
              return err
          }
          log.Printf("Sent %v bytes\n", n)
      }
  }
  ...
  </code></pre>
  
  <p>But the timeout is never triggered if the server goes away, instead the <code>Write</code> call will just block forever.</p>
  
  <ul>
  <li>What am I doing wrong with <code>SetWriteDeadline</code>?</li>
  <li>I want to kill the connection if the Write does not finish within the given timeout no matter what, if <code>SetWriteDeadline</code> is not the proper way to do that, how do I do it?</li>
  </ul>