diff --git a/daemon/HTTPServer.cpp b/daemon/HTTPServer.cpp index 27cbcd78..7a6c5c12 100644 --- a/daemon/HTTPServer.cpp +++ b/daemon/HTTPServer.cpp @@ -250,7 +250,7 @@ namespace http { break; case eRouterErrorNoDescriptors: s << " - " << tr("No Descriptors"); - break; + break; default: ; } } diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 109f8b88..555a5622 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -1424,19 +1424,20 @@ namespace transport else LogPrint (eLogError, "NTCP2: Connected from error ", ec.message ()); } - else - { - LogPrint (eLogError, "NTCP2: Accept error ", error.message ()); - if (error == boost::asio::error::no_descriptors) + else if (error == boost::asio::error::no_descriptors) + { + i2p::context.SetError (eRouterErrorNoDescriptors); + if (m_NoFileExhaustTimestamp < i2p::util::GetSecondsSinceEpoch () - NTCP2_DESCRIPTORS_EXHAUST_TIMEOUT) { - i2p::context.SetError (eRouterErrorNoDescriptors); - // TODO - return; - } - } - + m_NoFileExhaustTimestamp = i2p::util::GetSecondsSinceEpoch (); + LogPrint (eLogWarning, "NTCP2: WARNING! i2pd met file descriptors exhaustion! Please check your nofile limits!"); + } + } + else + LogPrint (eLogError, "NTCP2: Accept error ", error.message ()); + if (error != boost::asio::error::operation_aborted) - { + { if (!conn) // connection is used, create new one conn = std::make_shared (*this); else // reuse failed @@ -1463,22 +1464,26 @@ namespace transport } } else - LogPrint (eLogError, "NTCP2: Connected from error ", ec.message ()); + LogPrint (eLogError, "NTCP2: Connected from ipv6 error: ", ec.message ()); + } + else if (error == boost::asio::error::no_descriptors) + { + i2p::context.SetErrorV6 (eRouterErrorNoDescriptors); + if (m_NoFileExhaustTimestamp < i2p::util::GetSecondsSinceEpoch () - NTCP2_DESCRIPTORS_EXHAUST_TIMEOUT) + { + m_NoFileExhaustTimestamp = i2p::util::GetSecondsSinceEpoch (); + LogPrint (eLogWarning, "NTCP2: WARNING! i2pd met file descriptors exhaustion! Please check your nofile limits!"); + } } else - { - LogPrint (eLogError, "NTCP2: Accept ipv6 error ", error.message ()); - if (error == boost::asio::error::no_descriptors) - { - i2p::context.SetErrorV6 (eRouterErrorNoDescriptors); - // TODO - return; - } - } + LogPrint (eLogError, "NTCP2: Accept ipv6 error: ", error.message ()); if (error != boost::asio::error::operation_aborted) { - conn = std::make_shared (*this); + if (!conn) // connection is used, create new one + conn = std::make_shared (*this); + else // reuse failed + conn->Close (); m_NTCP2V6Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAcceptV6, this, conn, std::placeholders::_1)); } @@ -1728,7 +1733,7 @@ namespace transport }); boost::asio::async_read(conn->GetSocket(), boost::asio::buffer(readbuff->data (), SOCKS5_UDP_IPV4_REQUEST_HEADER_SIZE), // read min reply size - boost::asio::transfer_all(), + boost::asio::transfer_all(), [timer, conn, sz, readbuff](const boost::system::error_code & e, std::size_t transferred) { if (e) @@ -1736,7 +1741,7 @@ namespace transport else if (!(*readbuff)[1]) // succeeded { boost::system::error_code ec; - size_t moreBytes = conn->GetSocket ().available(ec); + size_t moreBytes = conn->GetSocket ().available(ec); if (moreBytes) // read remaining portion of reply if ipv6 received boost::asio::read (conn->GetSocket (), boost::asio::buffer(readbuff->data (), moreBytes), boost::asio::transfer_all (), ec); timer->cancel(); diff --git a/libi2pd/NTCP2.h b/libi2pd/NTCP2.h index 754f5a6d..c8c86e5d 100644 --- a/libi2pd/NTCP2.h +++ b/libi2pd/NTCP2.h @@ -43,6 +43,8 @@ namespace transport const int NTCP2_CLOCK_SKEW = 60; // in seconds const int NTCP2_MAX_OUTGOING_QUEUE_SIZE = 500; // how many messages we can queue up + const int NTCP2_DESCRIPTORS_EXHAUST_TIMEOUT = 60; // 1 minute + enum NTCP2BlockType { eNTCP2BlkDateTime = 0, @@ -286,6 +288,8 @@ namespace transport std::unique_ptr m_ProxyEndpoint; std::shared_ptr m_Address4, m_Address6, m_YggdrasilAddress; + uint64_t m_NoFileExhaustTimestamp; + public: // for HTTP/I2PControl