-
Notifications
You must be signed in to change notification settings - Fork 125
Remove eventLoop property from Task #82
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
Comments
One problem I see is that On the topic of connection generation code, why not add |
@artemredkin About
I have a preference for the second approach because it makes it a little clearer that the Ok, makes sense for not returning an optional. About the connection pool, you did mean adding it to the We could return a |
I gave my second idea a shot, here is the diff. |
also this discussion here because it's related: #79 |
@weissi Indeed, I realise its not a good solution to add |
Ok, we need to definitely think about this some more before 1.0.0. I don't have time right this second but will think about it soon. Adding other relevant folks @ianpartridge @tanner0101 @Lukasa to help the discussion. |
Some comments
The client should definitely be robust against that, this assumption is flawed. Back-pressure most of the time is exerted from another From what I can tell, having Because now it can change, we simply do this:
The HTTP client (I'll file a bug about this in a second) anyway needs to tolerate back-pressure futures from random ELs so there's no more room for user error. But in almost all cases, the user would use So tl;dr: Rename |
Thank you! I like this solution, it provides the right mix between correctness and usability in my opinion. Having the freedom of using any event loop (from On the same subject, I realise that |
Thanks for catching that. I think it's a bug that |
CC @artemredkin do you know why the constructor is public? |
Currently,
Task
has aneventLoop
stored property, and itschannel
must be on this same event loop.In practice,
eventLoop
can be used by the http client delegate in the following ways:eventLoop
.In these three cases, the goal to guarantee to the http client that it can assume all futures it gets from its delegate are already on the right event loop.
Potential shortcomings
Errors on user side
When applying back pressure, users getting futures from different event loops might forget to hop them back to the right event loop. On the other hand, if the client stopped relying on the assumption that futures returned from the delegate are already on the right event loop, and instead always took care of hopping them, this source of bugs would disappear entirely for a minimal performance cost (hopTo isn’t too heavy, and in many cases the user will need to use it either way, so why force them to do it when we could do this on the library side?).
Hard to compose with future evolutions
The
eventLoop
property might not compose very well with future evolutions of the client such as pooling (tldr: the associated event loop is hard to determine synchronously like Task needs, and Task might change of event loop during its lifetime):getConnection(for request: HTTPClient.Request -> EventLoopFuture<Connection>
, this is logical for it to return a future because a connection might not be instantly available, but it couldn’t be used as such with the current AsyncClient public API:execute()
synchronously returnsTask
, butTask
needs aneventLoop
on initialization, which couldn’t be instantaneously determined due togetConnection
being an async method. There would of be workarounds for this, but they would complicate the connection pool logic (maybe not a really good sign when two isolated components start to interact this way) and may also force creating new connections (instead of using released ones) just to satisfy the event loop identity constraint.Proposed solution
Remove
eventLoop
property entirely, always hop futures provided by the delegate, additionally, updateHTTPClientResponseDelegate
backpressure controlling methods to make them returnEventLoopFuture<Void>?
instead of a non-optionalEventLoopFuture<Void>
.This change would enable the following:
Task
less dependent on a specific event loop, making it easier to evolve in the future.task.channel.eventLoop
knowing it might evolve during theTask
lifetime.nil
instead of having to referenceeventLoop
just to return an immediately completed void future.What do you think about this? Am I missing some important part?
Thank you
The text was updated successfully, but these errors were encountered: