-
Notifications
You must be signed in to change notification settings - Fork 301
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
Update extensions
to be cloneable
#395
Comments
Some thoughts from an interested user: Given new requirement on extensions, a breaking change then? You would apply the same to It sounds like you would With synchronous corollaries, we would typically not clone an With clone in play, the Would the next breaking release also be time to consider integrating |
So I think the real goal here should be to make |
I've shared my opinion on
|
@davidbarsky the issue is that task/thread-locals don't work with most channel backed offtask clients like hyper and tower-buffer. While ext do work with this setup. They couple data that is specific to the user within the request.
Agreed, but there are special cases like gRPC where we have total control over this and could probably pull of some sneak stuff related to this. Having parts be clonable would be a huge help here. |
I mean its your choice how to implement clone, if memcpy is cheap then do that if arc bump is cheap then do that? |
Sure. In those cases, I think the appropriate course of action is to implement an extension trait that performs a
My argument boils down that we don't need to settle for just making |
I'm not convinced that task locals are an acceptable substitute for FWIW, when Linkerd's retry code "clones" requests, we just clone the parts + body, and create new extensions. A lot of the data we store in extensions is specific to an individual instance of a request — e.g. we want to record latencies for retries separately. |
@hawkw that seems like it could easily be done in a clone where you basically clear the data 👍 |
Agreed, maybe roughly implement like it does in |
extensions
to be cloneableextensions
to be cloneable?
A few options here:
3 would be my personal recommendation–very flexible going forward and allows users who have no desire to have request extensions at all (most customers?) to have a cloneable request without worrying about it. We can also do a minimal |
I think we can implement |
I've been planning to write up some thoughts, summarizing this thread next week, so we can arrive at a decision. One thing I think is missing is analyzing what extensions tend to be used for. That would help with deciding if they can be clone, if they can't what should they be instead, etc. For example, in hyper the I imagine people likely stick loaded context into them, such as a User that was loaded from the DB, or even a DB handle. Are those clone? There's likely good examples on linkerd2, and in the AWS SDK, and others. Such an analysis would help in deciding "should we". |
We exclusively use |
I'm mainly using them with axum's Still, requiring |
The |
I think that making an |
I mean, we could also just "not write code that clones requests" to get that behavior. :) |
That seems like something that can't quite be defined as
A potential problem is that everything using |
Yeah, that's right. I only brought this up to say "we probably would not actually use a |
I think making extensions generic is going to make writing tower layers in tower-http much more painful than the benefit. @hawkw can you implement that new request logic in terms of a non clonable wrapper? Like you can wrap your extension in a way that it reconstructs on clone rather than reusing? |
Context: I was a heavy user of Extensions at a Cloudflare where I wrote HTTP and gRPC backends. I no longer have any active projects that use Extensions as my current workplace uses Dropshot. All the items we put into On the other hand, some items we put into response extensions are !Clone, but as far as I understand that is not being proposed. |
The Clone would apply to both Request and Response. |
At least for us, the main reason we want clone is to easily recreate |
Actix Web doesn't use any of the higher-level constructs from this crate, including |
Ok. I can always Arc the response extension types. |
+1 for a |
Alright, it looks like the consensus is to move forward and require An asideI was curious if we could use Oh well. |
extensions
to be cloneable?extensions
to be cloneable
PR is up: #634 Will merge quickly, in case you want to chime in, since target launch is Nov 15. |
I propose that we move forward to allow
Request<B: Clone>
toimpl Clone
. The big blocker here is thatextensions
is not clonable. This could be fixed by making a AnyClone trait:The downside here is that all things you store in extensions is cloneable but I think this is a fair trade off since mostly its just information that could be thrown behind an arc or bytes.
cc @seanmonstar @carllerche @hawkw @davidbarsky
The text was updated successfully, but these errors were encountered: