-
Notifications
You must be signed in to change notification settings - Fork 610
Manage ICP ports using a Runner #2365
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT, the removed assert checked an invariant that this function still uses. The assert did not check everything it should have checked, but do we have to remove it in this PR?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The invariant I see here is that the outgoing port is already closed. Either by being the same object used by incoming port, or having closed already (eg by that read handler getting a 0-byte read). What else do you think also needs to be checked in order to close the outgoing port? |
||
|
|
||
| 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) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not clear to me what "graceful shutdown" implies in this context. Moreover, I do not think this function actually shuts down any ports -- the ports may continue to be open after this function returns. If fixing existing icpClosePorts() problems is outside this PR scope, then I recommend not adding any description of this problematic function in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words; the global port references are set to "closed" (for new activity), while the ports themselves are left to be closed "gracefully" (via RAII) when the last active transaction using them is done.