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

Upgrade Http::Stream::reply to Pointer #1855

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

Conversation

yadij
Copy link
Contributor

@yadij yadij commented Jun 29, 2024

Refactor to avoid storing a raw-pointer, with
missing reference-counting.

Refactor to avoid storing a raw-pointer, with
missing reference-counting.
@kinkie
Copy link
Contributor

kinkie commented Jun 29, 2024

This PR seems to contain spurious changes

@rousskov rousskov self-requested a review June 29, 2024 12:33
@rousskov rousskov changed the title Update Http::Stream::reply to Pointer Upgrade Http::Stream::reply to Pointer Jun 29, 2024
Copy link
Contributor

@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.

Thank you for this upgrade.

I replaced "update" with "upgrade" in PR title because the latter feels more precise and arguably self-documents the motivation behind this PR. Please undo if you think "update" is better.

src/http/Stream.cc Outdated Show resolved Hide resolved
src/http/Stream.cc Outdated Show resolved Hide resolved
if (http->request->range)
buildRangeHeader();

MemBuf *mb = reply->pack();
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible:

Suggested change
MemBuf *mb = reply->pack();
const auto mb = reply->pack();

Otherwise:

Suggested change
MemBuf *mb = reply->pack();
auto mb = reply->pack();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mb gets appended to below, going with the non-const variant.

Copy link
Contributor

Choose a reason for hiding this comment

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

mb gets appended to below, going with the non-const variant.

mb is not appended to. *mb is appended to. The change request was formulated correctly and still stands.

src/http/Stream.cc Show resolved Hide resolved
assert(rep);
MemBuf *mb = rep->pack();
reply = rep;
Copy link
Contributor

Choose a reason for hiding this comment

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

This HttpReply object may be passed from its raw/unprotected/lockless DeferredParams::reply storage to now-refconted Http::Stream::reply storage. I hope those deferred parameters always belong to the same Http::Stream object, but if they are not, then Http::Stream::reply object might be destroyed (via now-added Http::Stream::reply reference counting) before the corresponding DeferredParams object is destroyed, creating a dangling pointer inside DeferredParams storage. I recommend upgrading Http::Stream::DeferredParams::reply together with Http::Stream::reply (i.e. in this PR) to mitigate that risk.

Copy link
Contributor

@rousskov rousskov Jul 7, 2024

Choose a reason for hiding this comment

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

Looking at branch commit 7516249 (and, to a degree, its parent), it feels like something went wrong while upgrading Http::Stream::DeferredParams::reply storage. If possible, please avoid changing all (or the vast majority of) those functions! During these transitions, it is OK to pass a raw pointer (to a reference-counted HttpReply object) to legacy code that does not store that pointer or stores it properly. AFAICT, most of those modified functions fall into the former category. They should not be modified.

If there are some problems with that approach, let's discuss.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a chain reaction going on here. This is as small a chain of side effects as I can make it.

A) To fix the dangling pointer in Http::Stream::DeferredParams::reply update Http::Stream::DeferredParams::reply to RefCount.

That pushes the dangling pointer problem into ESIIncludeContext and Downloader where class methods using CSCB type for AsyncCall parameters as a raw-pointer (now the dangling one).

B) To fix (A) update CSCB definition to pass RefCount instead. Which pulls in all the CSCB functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a chain reaction going on here. This is as small a chain of side effects as I can make it.

Thank you for detailing this! I hope we can find a way to stop that chain reaction much sooner than branch commit 7516249 does:

A) To fix the dangling pointer in Http::Stream::DeferredParams::reply update Http::Stream::DeferredParams::reply to RefCount.

That pushes the dangling pointer problem into ESIIncludeContext and Downloader where class methods using CSCB type for AsyncCall parameters as a raw-pointer (now the dangling one).

CSCB callbacks are synchronous, right? When I look at Downloader changes in branch commit 7516249, I do not see any long-term HttpReply storage. I only see caller's reply pointer being forwarded to another synchronous call. That kind of forwarding, by itself, does not require smart pointers and does not create dangling raw pointers. Let's temporary assume, to simplify arguments, that downloaderRecipient() is the only CSCB callback in existence. Why do we have to change downloaderRecipient() and CSCB type after changing Http::Stream::DeferredParams::reply?

@rousskov rousskov added the S-waiting-for-author author action is expected (and usually required) label Jun 29, 2024
@squid-anubis squid-anubis added M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels and removed M-failed-other https://github.com/measurement-factory/anubis#pull-request-labels labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-for-author author action is expected (and usually required)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants