-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Stronger close()
semantics for TaskTracker
#6759
Comments
Alternative solution: Split API like a channel. |
Thanks for raising this. I'm wondering if this is highlighting a design mistake in If there's a sufficiently compelling design that isn't backwards-compatible, we could potentially make a 0.8.0 release using it. A breaking release of tokio-util is overdue anyway. |
Thanks again for raising this. There seems to be two important problems with
Proposal:
I also wonder if an additional method such as the one below would be helpful: Welcome suggestions, and am happy to implement whatever is decided. |
One concern I have is what happens to existing users that upgrade without changing their code. Right now, they might call |
Hmm I guess it would be a breaking change that breaks in a not nice way. I guess another benefit of this distinction might be clear syntax that would indicate how |
One possibility is to get rid of If we want to support closing the tracker, we could have a separate type that does support closing with your proposal. Or if we only want one type, maybe we rename the type to something else, or maybe we rename Basically, if we change the behavior, I'd like to make a change that breaks the compilation of existing users. |
Is your feature request related to a problem? Please describe.
TaskTracker
is a great solution for waiting for tasks to shutdown, but there's a race condition if used incorrectly. Take this codeIf we're unlucky, this program might experience the ordering
The
close()
name suggests slightly stronger semantics, similar to channel closure,which might suggest why this might be incorrectly relied upon.
Describe the solution you'd like
A stronger
token_if_not_closed()
API that returns aResult<TaskTrackerToken, TrackerCloseError>
.Internally it could perform:
This might cause some extra notifications to be triggered, but that seems OK to me.
Downsides here is that it would cause confusion with the 6 existing
spawn_...
family of functions. Unclear whether we should create a second TaskTracker with this api, or use the same TaskTracker with two sets of thespawn
functions.Describe alternatives you've considered
We could use
RwLock<TaskTracker>
ourselves to have much stronger semantics. Only close and wait onwrite
lock. Only spawn ontry_read
lock. Alternatively, we could use the token dance suggested above, but we miss out on the spawn convenience functions.Additional context
I noticed this desired while reviewing this commit: neondatabase/neon@d79da8f
Our internal discussions are available in the associated PR.
The text was updated successfully, but these errors were encountered: