-
-
Notifications
You must be signed in to change notification settings - Fork 973
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
Race condition when calling a side-effect of an AutoDisposeAsyncNotifierProvider #2506
Comments
Your provider got disposed, so it shouldn't be calling The error isn't the most user-friendly one, your You should handle the fact that the provider was canceled within the operation and act accordingly. To begin with, the pattern you've implemented in your |
I agree on that. but the error is just confusing as it's not related to using state setter. I was thinking this should work fine as the current behavior of using |
If you found a case where it doesn't throw, then that's a bug. It should. The error should be changed to something more reasonable, but you should definitely get an error. |
I think currently using
It's just ignored as we're checking for |
Ah well, my bad ha |
Removing this line from my sample above will let it work: state = const AsyncLoading(); Adding it causes the issue because it initializes if (completer != null) {
completer.complete(value.value);
_futureCompleter = null;
} |
Alright! no problem. but that mean we should be able to check for |
Check ref.onDispose |
I have the same issue. the provider is disposed while |
As Remi said you should check if the provider is disposed before setting the state. something like checking |
@AhmedLSayed9 Thank you, it's a bit cumbersome but it works for me. |
|
Discussed in #2502
Describe the bug
Running this will fail with an exception:
Bad state: Future already completed
What happens is:
1- The provider is initialized synchronously with 0
2-
state = const AsyncLoading();
get executed and initialize_futureCompleter
3- The provider get disposed after that (no listeners): dispose() method check and find that
_futureCompleter
has value but at the same time_lastFuture
is null (as the provider is synchronously initialized), so it completes_futureCompleter
with an error.4-
state = const AsyncData(0);
executes after than and find_futureCompleter
is not null so it completes it (again). Maybe_futureCompleter
should be set tonull
after completing it in the dispose method to fix this?I'm curious where's the other part of completing
_futureCompleter
when_lastFuture
is not null (commented here)Expected behavior
I except the code to run with no exception as the current behavior is suppressing the setter of a disposed provider without throwing an exception.
The text was updated successfully, but these errors were encountered: