title: Call SSL_shutdown() hang, client still in FIN_WAIT2 status
body: <p>In my ActiveUpdate module(download files from server), close OpenSSL connection will hang(wait beyond 2 hour) if server drop the FIN package.</p>
  
  <p>Pseudo code of SSL Connection close</p>
  
  <pre><code>def  ssl_close():
  if (!SSL_shutdown(m_ssl)):
      …
      shutdown(SSL_get_fd(m_ssl), SHUT_WR);
      SSL_shutdown(m_ssl)
      ...
  </code></pre>
  
  <p>netstat output for the hung connection</p>
  
  <pre><code>tcp        0      0 192.168.133.135:52453   10.203.136.169:4122     FIN_WAIT2   off (0.00/0/0)
  </code></pre>
  
  <blockquote>
    <p><a href="https://www.openssl.org/docs/ssl/SSL_shutdown.html" rel="nofollow">https://www.openssl.org/docs/ssl/SSL_shutdown.html</a></p>
    
    <p>In order to complete the bidirectional shutdown handshake, SSL_shutdown() must be called again. 
    If the underlying BIO is blocking, SSL_shutdown() will only return once the handshake step has been finished or an error occurred.</p>
  </blockquote>
  
  <p>If call SSL_shutdown() once, it will not hang, does it have any impact on memory and connection resources?</p>
  
  <p>Is there a timeout mechanism to control the SSL_shutdown() in OpenSSL, or a better way? </p>