Bug #11302 » 0005-Track-closing-ssl-connections-to-avoid-race.patch
src/http/Server.C | ||
---|---|---|
}
|
||
#ifdef HTTP_WITH_SSL
|
||
for (std::size_t i = 0; i < ssl_listeners_.size(); ++i) {
|
||
asio::ip::tcp::acceptor &acceptor = ssl_listeners_[i].acceptor;
|
||
SslConnectionPtr &new_connection = ssl_listeners_[i].new_connection;
|
||
for (auto &&ssl_listener: ssl_listeners_) {
|
||
asio::ip::tcp::acceptor &acceptor = ssl_listener.acceptor;
|
||
SslConnectionPtr &new_connection = ssl_listener.new_connection;
|
||
acceptor.async_accept(new_connection->socket(),
|
||
accept_strand_.wrap(
|
||
std::bind(&Server::handleSslAccept, this,
|
||
&ssl_listeners_[i],
|
||
&ssl_listener,
|
||
std::placeholders::_1)));
|
||
}
|
||
#endif // HTTP_WITH_SSL
|
||
... | ... | |
tcp_listeners_closed_.splice(tcp_listeners_closed_.end(), tcp_listeners_);
|
||
#ifdef HTTP_WITH_SSL
|
||
for (std::size_t i = 0; i < ssl_listeners_.size(); ++i)
|
||
ssl_listeners_[i].acceptor.close();
|
||
ssl_listeners_.clear();
|
||
for (auto &&ssl_listener: ssl_listeners_)
|
||
ssl_listener.acceptor.close();
|
||
ssl_listeners_closed_.splice(ssl_listeners_closed_.end(), ssl_listeners_);
|
||
#endif // HTTP_WITH_SSL
|
||
start();
|
||
... | ... | |
} else if (!listener->acceptor.is_open()) {
|
||
// server shutdown
|
||
LOG_DEBUG("handleSslAccept: async_accept error (acceptor closed, probably server shutdown): " << e.message());
|
||
auto ssl_listeners_closed_before = ssl_listeners_closed_.size();
|
||
ssl_listeners_closed_.remove_if([listener] (SslListener &t) { return &t == listener; });
|
||
auto ssl_listeners_closed_count = ssl_listeners_closed_before - ssl_listeners_closed_.size();
|
||
LOG_INFO("handleSslAccept: async_accept: acceptor closed, removed " << ssl_listeners_closed_count << " matching connections");
|
||
return;
|
||
} else {
|
||
LOG_ERROR("handleSslAccept: async_accept error: " << e.message());
|
||
... | ... | |
tcp_listeners_closed_.splice(tcp_listeners_closed_.end(), tcp_listeners_);
|
||
#ifdef HTTP_WITH_SSL
|
||
for (std::size_t i = 0; i < ssl_listeners_.size(); ++i)
|
||
ssl_listeners_[i].acceptor.close();
|
||
ssl_listeners_.clear();
|
||
for (auto &&ssl_listener: ssl_listeners_)
|
||
ssl_listener.acceptor.close();
|
||
ssl_listeners_closed_.splice(ssl_listeners_closed_.end(), ssl_listeners_);
|
||
#endif // HTTP_WITH_SSL
|
||
connection_manager_.stopAll();
|
src/http/Server.h | ||
---|---|---|
asio::ssl::context ssl_context_;
|
||
/// Acceptors used to listen for incoming https connections
|
||
std::vector<SslListener> ssl_listeners_;
|
||
std::list<SslListener> ssl_listeners_;
|
||
/// Acceptors that have been closed and are waiting asio acknowledgement of close
|
||
std::list<SslListener> ssl_listeners_closed_;
|
||
/// Add new SSL listener, called from start()
|
||
void addSslListener(asio::ip::tcp::resolver &resolver,
|