Make running out of file descriptors non fatal.

Fix a bug that kills the RPC door if it gets a prohibited connection
This commit is contained in:
JoelKatz
2012-12-21 07:38:51 -08:00
parent 7d7738a7fa
commit d34c0e6a45
5 changed files with 56 additions and 15 deletions

View File

@@ -11,11 +11,13 @@ using namespace std;
using namespace boost::asio::ip;
RPCDoor::RPCDoor(boost::asio::io_service& io_service) :
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT))
mAcceptor(io_service, tcp::endpoint(address::from_string(theConfig.RPC_IP), theConfig.RPC_PORT)),
mDelayTimer(io_service)
{
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
startListening();
}
RPCDoor::~RPCDoor()
{
cLog(lsINFO) << "RPC port: " << theConfig.RPC_IP << " " << theConfig.RPC_PORT << " allow remote: " << theConfig.RPC_ALLOW_REMOTE;
@@ -33,27 +35,42 @@ void RPCDoor::startListening()
bool RPCDoor::isClientAllowed(const std::string& ip)
{
if (theConfig.RPC_ALLOW_REMOTE) return(true);
if (ip=="127.0.0.1") return(true);
if (theConfig.RPC_ALLOW_REMOTE)
return true;
if (ip == "127.0.0.1")
return true;
return(false);
return false;
}
void RPCDoor::handleConnect(RPCServer::pointer new_connection,
const boost::system::error_code& error)
{
bool delay = false;
if (!error)
{
// Restrict callers by IP
if (!isClientAllowed(new_connection->getSocket().remote_endpoint().address().to_string()))
{
startListening();
return;
}
new_connection->connected();
}
else cLog(lsINFO) << "RPCDoor::handleConnect Error: " << error;
else
{
if (error == boost::system::errc::too_many_files_open)
delay = true;
cLog(lsINFO) << "RPCDoor::handleConnect Error: " << error;
}
startListening();
if (delay)
{
mDelayTimer.expires_from_now(boost::posix_time::milliseconds(1000));
mDelayTimer.async_wait(boost::bind(&RPCDoor::startListening, this));
}
else
startListening();
}
// vim:ts=4