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

remove Arc around RequestContext #558

Merged
merged 57 commits into from
Jan 19, 2023
Merged

remove Arc around RequestContext #558

merged 57 commits into from
Jan 19, 2023

Conversation

davepacheco
Copy link
Collaborator

This depends on #557. Leaving in "draft". This is a prototype.

This change removes the Arc around RequestContext in all of the request handler functions. This is something I've been meaning to revisit for a while but it came up while doing #557, etc.

On the one hand, I think this is a good change in isolation: nobody else has a reference to this object, and in fact the whole point of this object is to encapsulate for the request handler whatever Dropshot wants to pass to it for this request. So it doesn't make sense for Dropshot to hold its own reference to it. Dropshot can keep copies or references to whatever things inside the RequestContext that it wants. It's simpler for everybody to get rid of this Arc and it makes it less likely that people will accidentally hang onto copies of it.

The main downside is that this change has a big blast radius for consumers -- literally every endpoint function has to change. But the change is trivial and any mistakes would be caught at compile-time. I used this vim command: %s/Arc<RequestContext<\([^>]*\)>>/RequestContext<\1>/gc. Another option would be to explore supporting both forms, but that feels more confusing going forward.

I also considered making it &RequestContext. I'm not sure what the right lifetime for that would be, if you wanted to make it explicit. And again, my thought was: dropshot has created this object for you, so why not let you have it? In retrospect I wish most of the fields themselves were references (or that we only exposed references). Maybe if we did that and only gave you &RequestContext<'a>, then we could actually prevent leakage of these fields without you explicitly cloning them. That'd be a bigger change for consumers using these fields.

Thoughts? (CC @ahl)

Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

looks good

@davepacheco davepacheco marked this pull request as ready for review January 18, 2023 17:59
Base automatically changed from remove-rq to main January 19, 2023 01:14
@davepacheco davepacheco merged commit af0f37c into main Jan 19, 2023
@davepacheco davepacheco deleted the remove-arc-rqctx branch January 19, 2023 03:18
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