title: Socat not closing tcp connection
body: <p>I use <code>socat 1.7.3.1-r0</code> and run following command on an <code>alpine 3.3</code> linux server:</p>
  
  <pre><code>socat -d -d -d PTY,link=/dev/ttyFOOBAR,echo=0,raw,unlink-close=0 TCP-LISTEN:7000,forever,reuseaddr
  </code></pre>
  
  <p><code>Socat</code> will listen for clients and create a bidirectional communication by passing data from the virtual serial port <code>/dev/ttyFOOBAR</code> to the client and back again over TCP. Once the client disconnects <code>socat</code> should exit.</p>
  
  <p>When such a connection is established socat logs the following:</p>
  
  <blockquote>
  <pre><code>I socat by Gerhard Rieger - see www.dest-unreach.org
  I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
  I This product includes software written by Tim Hudson (tjh@cryptsoft.com)
  I setting option "symbolic-link" to "/dev/ttyFOOBAR"
  I setting option "echo" to 0
  I setting option "raw"
  I setting option "unlink-close" to 0
  I openpty({5}, {6}, {"/dev/pts/3"},,) -&gt; 0
  N PTY is /dev/pts/3
  I setting option "forever" to 1
  I setting option "so-reuseaddr" to 1
  I socket(2, 1, 6) -&gt; 7
  I starting accept loop
  N listening on AF=2 0.0.0.0:7000
  I accept(7, {2, AF=2 CLIENT_IP:PORT}, 16) -&gt; 8
  N accepting connection from AF=2 CLIENT_IP:PORT on AF=2 172.20.0.2:7000
  I permitting connection from AF=2 CLIENT_IP:PORT
  I close(7)
  I resolved and opened all sock addresses
  N starting data transfer loop with FDs [5,5] and [8,8]
  </code></pre>
  </blockquote>
  
  <p><code>ss</code> command on the server prints:</p>
  
  <pre><code>Netid  State      Recv-Q Send-Q Local Address:Port                 Peer Address:Port                
  tcp    ESTAB      0      0      172.20.0.2:7000                 CLIENT_IP:PORT
  </code></pre>
  
  <p>The problem is, that when I disconnect the client (by switching it off), the tcp connection is still established and no addition logging is coming from socat. <code>ss</code> still shows the connection as ESTAB. Any ideas why? When I again connect the client following appears in the logs:</p>
  
  <pre><code>W read(8, 0x7fa8f48c4020, 8192): Connection reset by peer
  N socket 2 to socket 1 is in error
  N socket 2 (fd 8) is at EOF
  I poll timed out (no data within 0.500000 seconds)
  I close(5)
  I shutdown(8, 2)
  I shutdown(8, 2): Socket not connected
  N exiting with status 0
  </code></pre>
  
  <p>But why does this happen on connect instead of disconnect?</p>