在我的 ActiveUpdate 模块(从服务器下载文件)中,如果服务器丢弃 FIN 包,关闭 OpenSSL 连接将挂起(等待超过 2 小时)。
SSL连接关闭伪代码
def ssl_close():
if (!SSL_shutdown(m_ssl)):
…
shutdown(SSL_get_fd(m_ssl), SHUT_WR);
SSL_shutdown(m_ssl)
...
挂起连接的 netstat 输出
tcp 0 0 192.168.133.135:52453 10.203.136.169:4122 FIN_WAIT2 off (0.00/0/0)
https://www.openssl.org/docs/ssl/SSL_shutdown.html
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.
调用一次SSL_shutdown()不会挂起,对内存和连接资源有影响吗?
有没有超时机制来控制 OpenSSL 中的 SSL_shutdown(),或者更好的方法?
最佳答案
第一个 SSL_shutdown 将导致向对等方发送关闭警报,以向对等方发出不再有 SSL 数据到来的信号 - 类似于发送 FIN 或在普通套接字上执行关闭 SHUT_WR。第二个 SSL_shutdown 将等待,直到它收到来自对等方的关闭警报。
为确保套接字完全事件以便对等方发送 SSL 关闭警报并且您将收到它,我建议仅在第二次 SSL_shutdown 完成后关闭底层套接字。 IE。首先将套接字从 SSL 完全降级为普通套接字,然后关闭普通套接字。
关于ssl - 调用 SSL_shutdown() 挂起,客户端仍处于 FIN_WAIT2 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25050425/