diff --git a/src/ICP.h b/src/ICP.h index 10a8e1c673b..e70944e3c96 100644 --- a/src/ICP.h +++ b/src/ICP.h @@ -114,10 +114,8 @@ void icpHandleIcpV3(int, Ip::Address &, char *, int); void icpOpenPorts(void); /// \ingroup ServerProtocolICPAPI -void icpConnectionShutdown(void); - -/// \ingroup ServerProtocolICPAPI -void icpClosePorts(void); +/// Perform a graceful shutdown of ICP listening and sending ports (if any) +void icpClosePorts(); /// \ingroup ServerProtocolICPAPI int icpSetCacheKey(const cache_key * key); diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 2a4ced3bfab..86eee2a998c 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -18,6 +18,7 @@ #include "acl/Acl.h" #include "acl/FilledChecklist.h" #include "base/AsyncCallbacks.h" +#include "base/RunnersRegistry.h" #include "client_db.h" #include "comm.h" #include "comm/Connection.h" @@ -677,6 +678,9 @@ icpHandleUdp(int sock, void *) void icpOpenPorts(void) { + if (IamWorkerProcess()) + return; + uint16_t port; if ((port = Config.Port.icp) <= 0) @@ -752,13 +756,12 @@ icpIncomingConnectionOpened(Ipc::StartListeningAnswer &answer) } } -/** - * icpConnectionShutdown only closes the 'in' socket if it is - * different than the 'out' socket. - */ void -icpConnectionShutdown(void) +icpClosePorts() { + if (!IamWorkerProcess()) + return; + if (!Comm::IsConnOpen(icpIncomingConn)) return; @@ -776,22 +779,23 @@ icpConnectionShutdown(void) * to that specific interface. During shutdown, we must * disable reading on the outgoing socket. */ - assert(Comm::IsConnOpen(icpOutgoingConn)); - - Comm::SetSelect(icpOutgoingConn->fd, COMM_SELECT_READ, nullptr, nullptr, 0); -} - -void -icpClosePorts(void) -{ - icpConnectionShutdown(); + if (Comm::IsConnOpen(icpOutgoingConn)) { + Comm::SetSelect(icpOutgoingConn->fd, COMM_SELECT_READ, nullptr, nullptr, 0); - if (icpOutgoingConn != nullptr) { debugs(12, DBG_IMPORTANT, "Stop sending ICP from " << icpOutgoingConn->local); icpOutgoingConn = nullptr; } } +class IcpRr : public RegisteredRunner +{ + void useConfig() override { icpOpenPorts(); } + void startReconfigure() override { icpClosePorts(); } + void syncConfig() override { icpOpenPorts(); } + void endingShutdown() override { icpClosePorts(); } +}; +DefineRunnerRegistrator(IcpRr); + static void icpCount(void *buf, int which, size_t len, int delay) { diff --git a/src/main.cc b/src/main.cc index c9ad17f905d..c097d169d20 100644 --- a/src/main.cc +++ b/src/main.cc @@ -776,7 +776,6 @@ serverConnectionsOpen(void) // start various proxying services if we are responsible for them if (IamWorkerProcess()) { clientOpenListenSockets(); - icpOpenPorts(); icmpEngine.Open(); netdbInit(); Acl::Node::Initialize(); @@ -791,7 +790,6 @@ serverConnectionsClose(void) if (IamWorkerProcess()) { clientConnectionsClose(); - icpConnectionShutdown(); icmpEngine.Close(); } } @@ -809,7 +807,6 @@ mainReconfigureStart(void) // Initiate asynchronous closing sequence serverConnectionsClose(); - icpClosePorts(); #if USE_OPENSSL Ssl::TheGlobalContextStorage().reconfigureStart(); #endif @@ -1396,6 +1393,7 @@ RegisterModules() #if USE_HTCP CallRunnerRegistrator(HtcpRr); #endif + CallRunnerRegistrator(IcpRr); #if USE_OPENSSL CallRunnerRegistrator(sslBumpCfgRr); #endif @@ -2015,7 +2013,6 @@ SquidShutdown() #endif redirectShutdown(); externalAclShutdown(); - icpClosePorts(); releaseServerSockets(); commCloseAllSockets(); diff --git a/src/tests/stub_icp.cc b/src/tests/stub_icp.cc index 44091838b58..95930245852 100644 --- a/src/tests/stub_icp.cc +++ b/src/tests/stub_icp.cc @@ -35,7 +35,6 @@ void icpCreateAndSend(icp_opcode, int, char const *, int, int, int, const Ip::Ad icp_opcode icpGetCommonOpcode() STUB_RETVAL(ICP_INVALID) void icpDenyAccess(Ip::Address &, char *, int, int) STUB void icpHandleIcpV3(int, Ip::Address &, char *, int) STUB -void icpConnectionShutdown(void) STUB int icpSetCacheKey(const cache_key *) STUB_RETVAL(0) const cache_key *icpGetCacheKey(const char *, int) STUB_RETVAL(nullptr) diff --git a/src/tools.cc b/src/tools.cc index a828805581f..dc257f0540b 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -97,9 +97,6 @@ releaseServerSockets(void) // clear http_port, https_port, and ftp_port lists clientConnectionsClose(); - // clear icp_port's - icpClosePorts(); - // XXX: Why not the HTCP, SNMP, DNS ports as well? // XXX: why does this differ from main closeServerConnections() anyway ? }