-
Notifications
You must be signed in to change notification settings - Fork 516
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
base: master
Are you sure you want to change the base?
Conversation
Refactor to avoid storing a raw-pointer, with missing reference-counting.
This PR seems to contain spurious changes |
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.
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
if (http->request->range) | ||
buildRangeHeader(); | ||
|
||
MemBuf *mb = reply->pack(); |
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.
If possible:
MemBuf *mb = reply->pack(); | |
const auto mb = reply->pack(); |
Otherwise:
MemBuf *mb = reply->pack(); | |
auto mb = reply->pack(); |
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.
mb
gets appended to below, going with the non-const variant.
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.
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.
assert(rep); | ||
MemBuf *mb = rep->pack(); | ||
reply = rep; |
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.
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.
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.
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.
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.
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.
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.
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
updateHttp::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?
Refactor to avoid storing a raw-pointer, with
missing reference-counting.