-
Notifications
You must be signed in to change notification settings - Fork 636
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
Wake
impl for Waker
should hold a weak reference
#853
Comments
It's critical to hold a strong reference, because at least some executors don't keep a handle to blocked tasks; the fact that you have FWIW, nothing here has changed from futures 0.1. |
Alright, it isn't critical as I can just use the unsafe trait. I would just say that this behavior does not make it possible to implement a clean shutdown for an executor (as the tasks cannot be dropped). |
@carllerche Do you understand the issue I'm raising though? I don't think it's an option to change this. Also, why not just keep the underlying future in an |
@aturon I understand the issue. In my opinion, if one relies on this behavior, it implies the executor does not correctly implement a shutdown process. Either way, I can rely on the unsafe trait. |
@carllerche To clarify: I think you're saying that an executor that wants to implement shutdown needs to keep a the single strong reference to all tasks ever spawned. But doesn't that create potential for leakage? If a task is blocked, and all |
@aturon It depends on the executor's impl detail, but I plan on signalling the executor which then performs cleanup. Also, all wakers dropping before the future completing is indicative of a bug. |
Ahha, you're right -- I was thinking about this from the future side, not the task side. Makes sense. Ok so with all of that, I think it may indeed be worth changing this. @cramertj any thoughts? |
@aturon It breaks futures-cpupool and it would break my current fuchsia executor, but the change doesn't seem unreasonable and the fix is fairly easy. For the sake of clarification: right now Or would
The |
@cramertj yes, I know that when the future is completed, it is dropped. My point is, with the thread pool as it is implemented today, when the pool is dropped the workers shutdown, but all spawned futures are not touched, so they can stay around for arbitrary amounts of time. |
Keeping weak references in |
Yup, if you're creating and deleting pools, this will leak tasks. I guess it's a matter of deciding what is more important: the extra atomic ops, or consistent cleanup. Note that you could implement a system for opting into cleanup by storing an I think I don't care too much either way here, so if you or @aturon have a strong preference I'm fine going w/ that. |
Yes, but IMO that doesn't mean that the provided ThreadPool should leak in those cases. Either way, as I mentioned earlier, you can achieve either option by using
|
@carllerche Yup, I agree with your summary. i'm fine with either behavior. |
Thanks all. After this thread, I feel pretty comfortable with the defaults we've chosen, rather than imposing the upgrade costs across the board. I'm going to close this out. |
Just a thought, but it seems possibly better to default to safer (slash not leaking), and allow implementations who know better to opt-in to that with the unsafe trait. It should be harder to write those bugs, not easier. |
Looking at the implementation of
Wake
forArcWrapped
, it looks like it holds a strong reference of theWake
instance.Since the
Wake
instance is usually the task, containing the future, and all associated state, it seems like wakers should hold a weak reference.There could be an arbitrary number of wake handles around for arbitrary amounts of time. Holding a strong reference will prevent the task state from being cleared.
The text was updated successfully, but these errors were encountered: