diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index 4cbb4631..0cce293e 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -157,9 +157,19 @@ namespace client SocketsPipe(I2PService * owner, std::shared_ptr upstream, std::shared_ptr downstream): I2PServiceHandler(owner), m_up(upstream), m_down(downstream) { - boost::asio::socket_base::receive_buffer_size option(SOCKETS_PIPE_BUFFER_SIZE); - upstream->set_option(option); - downstream->set_option(option); + try + { + boost::asio::socket_base::receive_buffer_size option(SOCKETS_PIPE_BUFFER_SIZE); + upstream->set_option(option); + downstream->set_option(option); + } + catch (boost::system::system_error& ex) + { + std::string name; + if (GetOwner ()) + name = GetOwner ()->GetName (); + LogPrint(eLogWarning, "SocketsPipe: ", name, " failed to set receive buffer size: " , ex.what()); + } } ~SocketsPipe() { Terminate(); } diff --git a/libi2pd_client/SOCKS.cpp b/libi2pd_client/SOCKS.cpp index 27a35728..6e4a2d77 100644 --- a/libi2pd_client/SOCKS.cpp +++ b/libi2pd_client/SOCKS.cpp @@ -831,6 +831,15 @@ namespace proxy template void SOCKSHandler::SocksUpstreamSuccess(std::shared_ptr& upstreamSock) { + if (!m_sock->is_open ()) + { + // check if the socket got closed during upstream handshake + LogPrint(eLogWarning, "SOCKS: Can't link to upstream because socket is closed"); + upstreamSock = nullptr; + m_sock = nullptr; + Terminate(); + return; + } LogPrint(eLogInfo, "SOCKS: Upstream success"); boost::asio::const_buffer response(nullptr, 0); switch (m_socksv)