Skip to content

Commit 7eb49c7

Browse files
committed
Merge pull request #4358
6afa493 rpc: Add acceptors only when listening succeeded (Wladimir J. van der Laan) 33e5b42 rpc: Ignore and log errors during cancel (Wladimir J. van der Laan)
2 parents 9fe80a2 + 6afa493 commit 7eb49c7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/rpcserver.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ void StartRPCThreads()
642642
LogPrintf("Binding RPC on address %s port %i (IPv4+IPv6 bind any: %i)\n", bindAddress.to_string(), endpoint.port(), bBindAny);
643643
boost::system::error_code v6_only_error;
644644
boost::shared_ptr<ip::tcp::acceptor> acceptor(new ip::tcp::acceptor(*rpc_io_service));
645-
rpc_acceptors.push_back(acceptor);
646645

647646
try {
648647
acceptor->open(endpoint.protocol());
@@ -658,6 +657,7 @@ void StartRPCThreads()
658657
RPCListen(acceptor, *rpc_ssl_context, fUseSSL);
659658

660659
fListening = true;
660+
rpc_acceptors.push_back(acceptor);
661661
// If dual IPv6/IPv4 bind succesful, skip binding to IPv4 separately
662662
if(bBindAny && bindAddress == asio::ip::address_v6::any() && !v6_only_error)
663663
break;
@@ -700,11 +700,20 @@ void StopRPCThreads()
700700
// First, cancel all timers and acceptors
701701
// This is not done automatically by ->stop(), and in some cases the destructor of
702702
// asio::io_service can hang if this is skipped.
703+
boost::system::error_code ec;
703704
BOOST_FOREACH(const boost::shared_ptr<ip::tcp::acceptor> &acceptor, rpc_acceptors)
704-
acceptor->cancel();
705+
{
706+
acceptor->cancel(ec);
707+
if (ec)
708+
LogPrintf("%s: Warning: %s when cancelling acceptor", __func__, ec.message());
709+
}
705710
rpc_acceptors.clear();
706711
BOOST_FOREACH(const PAIRTYPE(std::string, boost::shared_ptr<deadline_timer>) &timer, deadlineTimers)
707-
timer.second->cancel();
712+
{
713+
timer.second->cancel(ec);
714+
if (ec)
715+
LogPrintf("%s: Warning: %s when cancelling timer", __func__, ec.message());
716+
}
708717
deadlineTimers.clear();
709718

710719
rpc_io_service->stop();

0 commit comments

Comments
 (0)