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

De-duplicate I/O error-detailing code #247

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

Conversation

eduard-bagdasaryan
Copy link

This improvement eliminates code duplication introduced
by b850f8b fix.

This improvement eliminates code duplication introduced
by b850f8b fix.
@rousskov rousskov changed the base branch from master to SQUID-939-bug-5329 March 4, 2024 13:39
@rousskov rousskov changed the base branch from SQUID-939-bug-5329 to master March 4, 2024 13:39
lte.timedout = io.xerrno == ETIMEDOUT;
lte.aborted = !lte.timedout; // intentionally true for zero io.xerrno
terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), lte);
terminateWithError(ERR_WRITE_ERROR, io.xerrno);
Copy link

Choose a reason for hiding this comment

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

I would like to avoid adding a second terminateX() method just to encapsulate Error and LogTagsErrors creation code, especially when that encapsulation moves us back from a flexible/safe/explicit ErrorDetail API to none-of-those-things int-is-errno API. Adding terminateX() may also encourage creation of terminateY() and terminateZ() to accommodate other error detail construction cases, and we do not want that kind of API fan-out.

I realize that part of the appeal here is how LogTagsErrors objects are initialized from errno. I am pretty sure that code should eventually disappear because we can compute the same log tags based on the information stored in Error. However, polishing that aspect will result in more changes than I would like to see in this particular PR.

Instead of adding terminateWithError(), please add and use a LogTagsErrors::FromErrno() static method that returns a properly configured LogTagsErrors object. Doing so will arguably leave some of the logic duplicated, but I think it is better than adding a competing terminateX() interface with raw errno argument.

Suggested change
terminateWithError(ERR_WRITE_ERROR, io.xerrno);
terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), LogTagsErrors::FromErrno(io.xerrno));

Copy link
Author

Choose a reason for hiding this comment

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

Done (5a03963).

src/servers/Server.cc Outdated Show resolved Hide resolved
src/LogTags.h Outdated Show resolved Hide resolved
lte.timedout = io.xerrno == ETIMEDOUT;
lte.aborted = !lte.timedout; // intentionally true for zero io.xerrno
terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), lte);
terminateAll(Error(ERR_WRITE_ERROR, SysErrorDetail::NewIfAny(io.xerrno)), LogTagsErrors::FromErrno(io.xerrno));
return;
Copy link

Choose a reason for hiding this comment

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

Is it possible to do something about ERR_READ_TIMEOUT case (e.g., make sure it always has ETIMEDOUT) so that we can refactor FwdState::updateAleWithFinalError() to use the new method as well?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think that ERR_READ_TIMEOUT will be always paired with ETIMEDOUT. ERR_READ_TIMEOUT is set in Ftp::Client::timeout() and HttpStateData::httpTimeout() - this code reflects Squid-configuration level timeouts whereas ETIMEDOUT reflects TCP-level timeouts.

Copy link

Choose a reason for hiding this comment

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

I do not disagree, but LogTagsErrors do need to signal a TIMEOUT suffix for both kinds of timeouts. Should FwdState::updateAleWithFinalError() do something like the following to simplify that code logic and reduce its duplication?

const auto lte = LogTagsErrors::FromErrno(err->type == ERR_READ_TIMEOUT ? ETIMEOUT : err->xerrno);

The above sketch effectively removes the ERR_NONE check in the existing code. I could not quickly figure out why we added that part of the check in recent commit 21f9015. Can you?

Copy link
Author

Choose a reason for hiding this comment

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

why we added that part of the check in recent commit 21f9015

No, I could not find an explanation. It was added in the initial PR186 commit. Maybe some of ErrorState() creators called constructed it with ERR_NONE then? I looked through these callers now and could not find any. Anyway, I think it is better to reduce the code duplication as you suggested.

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