Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediately close bad connections to prevent file exhaustion #6112

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Changes from 5.25.0
- API:
- FIXED: Allow for special characters in the profile/method as part of the HTTP URL. [#6090](https://github.com/Project-OSRM/osrm-backend/pull/6090)
- FIXED: Set osrm-routed to immediately close bad connections [#6112](https://github.com/Project-OSRM/osrm-backend/pull/6112)
- Build:
- CHANGED: Replace Travis with Github Actions for CI builds [#6071](https://github.com/Project-OSRM/osrm-backend/pull/6071)
- FIXED: Fixed Boost link flags in pkg-config file. [#6083](https://github.com/Project-OSRM/osrm-backend/pull/6083)
Expand Down
4 changes: 4 additions & 0 deletions include/server/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class Server
new_connection->socket(),
boost::bind(&Server::HandleAccept, this, boost::asio::placeholders::error));
}
else
{
util::Log(logERROR) << "HandleAccept error: " << e.message();
}
}

unsigned thread_pool_size;
Expand Down
16 changes: 13 additions & 3 deletions src/server/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
#include "server/request_parser.hpp"

#include <boost/algorithm/string/predicate.hpp>
#include <boost/assert.hpp>
#include <boost/bind.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>

#include <iterator>
#include <string>
#include <vector>

namespace osrm
Expand Down Expand Up @@ -48,6 +45,12 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
{
if (error)
{
if (error != boost::asio::error::operation_aborted)
{
// Error not triggered by timer expiry, commence connection shutdown.
util::Log(logDEBUG) << "Connection read error: " << error.message();
handle_shutdown();
}
return;
}

Expand All @@ -73,6 +76,7 @@ void Connection::handle_read(const boost::system::error_code &error, std::size_t
current_request.endpoint = TCP_socket.remote_endpoint(ec).address();
if (ec)
{
util::Log(logDEBUG) << "Socket remote endpoint error: " << ec.message();
handle_shutdown();
return;
}
Expand Down Expand Up @@ -165,6 +169,10 @@ void Connection::handle_write(const boost::system::error_code &error)
handle_shutdown();
}
}
else
{
util::Log(logDEBUG) << "Connection write error: " << error.message();
}
}

/// Handle completion of a timeout timer..
Expand All @@ -183,6 +191,8 @@ void Connection::handle_timeout(boost::system::error_code ec)

void Connection::handle_shutdown()
{
// Cancel timer to ensure all resources are released immediately on shutdown.
timer.cancel();
// Initiate graceful connection closure.
boost::system::error_code ignore_error;
TCP_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignore_error);
Expand Down