From eec34e3ac3cbf48461b24d0864ae1ba502a5db8f Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 20 Feb 2018 08:40:47 +0100 Subject: [PATCH] fix issue with SSL tracker connections left in CLOSE_WAIT state (#2797) --- ChangeLog | 1 + src/socket_type.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index abb2dfb13..5e26424d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * fix issue with SSL tracker connections left in CLOSE_WAIT state * defer truncating existing files until the first time we write to them * fix issue when receiving a torrent with 0-sized padfiles as magnet link * fix issue resuming 1.0.x downloads with a file priority 0 diff --git a/src/socket_type.cpp b/src/socket_type.cpp index 2da3327a5..1a7a41326 100644 --- a/src/socket_type.cpp +++ b/src/socket_type.cpp @@ -139,6 +139,8 @@ namespace libtorrent #ifdef TORRENT_USE_OPENSSL namespace { + void nop(boost::shared_ptr) {} + void on_close_socket(socket_type* s, boost::shared_ptr) { #if defined TORRENT_ASIO_DEBUGGING @@ -165,9 +167,16 @@ namespace libtorrent #define MAYBE_ASIO_DEBUGGING #endif + char const buffer[] = ""; + // chasing the async_shutdown by a write is a trick to close the socket as + // soon as we've sent the close_notify, without having to wait to receive a + // response from the other end + // https://stackoverflow.com/questions/32046034/what-is-the-proper-way-to-securely-disconnect-an-asio-ssl-socket + #define CASE(t) case socket_type_int_impl >::value: \ MAYBE_ASIO_DEBUGGING \ - s.get >()->async_shutdown(boost::bind(&on_close_socket, &s, holder)); \ + s.get >()->async_shutdown(boost::bind(&nop, holder)); \ + s.get >()->async_write_some(boost::asio::buffer(buffer), boost::bind(&on_close_socket, &s, holder)); \ break; switch (s.type())