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

Do not collapse ssl_crtd requests across reconfigurations 2 #228

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

eduard-bagdasaryan
Copy link

@eduard-bagdasaryan eduard-bagdasaryan commented Sep 14, 2023

Squid collapses ssl_crtd requests on a pending request with an identical
helper query. This collapsing “works” across Squid reconfigurations even
though the old helper responsible for the first request is replaced with
a new one during reconfiguration; that old helper must complete
servicing pending requests.

However, since the helper program itself could have been changed (just
prior to reconfiguration), it is conceptually wrong for
post-reconfiguration requests to reuse the old helper program response:
Squid must conservatively assume that the response may have changed
because the helper protocol does not allow Squid to validate the
freshness of the helper response (to a collapsed request). Such blind
reuse also creates runtime problems if a buggy helper never responds to
a request X, stalling all the new requests getting collapsed on X (until
a Squid restart).

To avoid this post-reconfiguration collapsing, we now switch to a new
GeneratorRequests object during reconfiguration, instead of keeping
all collapsed requests in a global GeneratorRequests object.

In this new approach each Ssl::Helper object has its own
GeneratorRequests map (used for collapsing).  Since a reconfiguration
creates a new Sll::Helper, the collapsed request are not shared across
reconfigurations.
src/helper.cc Outdated
@@ -132,7 +132,7 @@ HelperServerBase::dropQueued()
void *cbdata;
if (cbdataReferenceValidDone(r->request.data, &cbdata)) {
r->reply.result = Helper::Unknown;
r->request.callback(cbdata, r->reply);
parentHelper()->callBack(r->request.callback, cbdata, r->reply);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a virtual parentHelper() -- a red flag for several reasons -- I would rather add a Helper::Client reference as a dropQueued() parameter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in PR229.

src/helper.cc Outdated
result = Helper::Unknown;
callback(data, Helper::Reply(Helper::Unknown));
} else { // pretend the helper has responded with ERR
hlp->callBack(callback, data, Helper::Reply(Helper::Error));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not send answers to never-submitted queries through the helper. Keep the old direct callback-calling code virtually unchanged here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left this code as-is in PR229..

src/helper.cc Outdated
@@ -576,6 +574,12 @@ helper::submit(const char *buf, HLPCB * callback, void *data)
debugs(84, DBG_DATA, Raw("buf", buf, strlen(buf)));
}

void
helper::callBack(HLPCB *callback, void *data, const Helper::Reply &reply)
Copy link

@rousskov rousskov Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely, this method should take just Xaction or Request+Reply parameters, not raw data+Reply.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without SubmissionFailure() changes, we do not need these parameters of course. In PR229, callBack() takes a single Xaction * argument.

Copy link

@rousskov rousskov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one problem that, if confirmed, will require refactoring and research. The rest is minor style polishing.

src/ssl/helper.h Outdated
/**
* Set of thread for ssl_crtd. This class is singleton.
* This class use helper structure for threads management.
*/
class Helper
class Helper : public ::Helper::Client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this formatting variation for new and modified class declarations:

Suggested change
class Helper : public ::Helper::Client
class Helper: public ::Helper::Client

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.h Show resolved Hide resolved
src/ssl/helper.h Outdated
/// query:GeneratorRequest map
using GeneratorRequests = std::unordered_map<SBuf, GeneratorRequest*>;

explicit Helper(const char *name): Helper::Client(name) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
explicit Helper(const char *name): Helper::Client(name) {}
explicit Helper(const char * const name): Helper::Client(name) {}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.h Outdated
static Pointer Make(const char *name) { return new Helper(name); }

/// pending Helper requests (to all certificate generator helpers combined)
GeneratorRequests generatorRequests;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, please make this and related type alias declaration private.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.h Show resolved Hide resolved
src/ssl/helper.cc Show resolved Hide resolved
Copy link
Author

@eduard-bagdasaryan eduard-bagdasaryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (up to 98d2d9a).

src/ssl/helper.h Outdated
/**
* Set of thread for ssl_crtd. This class is singleton.
* This class use helper structure for threads management.
*/
class Helper
class Helper : public ::Helper::Client
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.h Show resolved Hide resolved
src/ssl/helper.h Outdated
/// query:GeneratorRequest map
using GeneratorRequests = std::unordered_map<SBuf, GeneratorRequest*>;

explicit Helper(const char *name): Helper::Client(name) {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.h Show resolved Hide resolved
src/ssl/helper.h Outdated
static Pointer Make(const char *name) { return new Helper(name); }

/// pending Helper requests (to all certificate generator helpers combined)
GeneratorRequests generatorRequests;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

src/ssl/helper.cc Show resolved Hide resolved
eduard-bagdasaryan and others added 3 commits October 4, 2023 22:52
Now it is unlocked before it gets deleted in Ssl::HandleGeneratorReply().
With the previous approach, it was unlocked in Helper::Request
destructor after Ssl::HandleGeneratorReply() - the memory would not
leak in this case. The updated callBack() looks more in line with
the base Helper::Client::callBack().
eduard-bagdasaryan and others added 5 commits October 17, 2023 16:21
We must remove GeneratorRequest object (and clear its
generatorRequests map entry) if Helper::Client::trySubmit()
returns an error or throws.
Temporalily added compiler '-H' option to
figure out why sbuf/Algorithms.h is missed on the
buildserver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants