opened
lpyvvvvvv
username_0
there are two silos, siloA and siloB. 
grainA on siloA.
then shutdown siloA, sometimes grainA  OnActivate on siloB before OnDeactivate on slioA.
Is there any way to solve this issue?
problem when shutdown silo
issue
created
Cloud33
username_1
When you close silos, `OnDeactivateasync` cannot be guaranteed to trigger. This is a best effort behavior.


You may have to change the method, such as calling `WriteStateAsync` synchronously when the data changes
comment
created
sergeybykov
username_2
+1
The general rule is to persist any state that you don't want to lose as part of the operation that updates it.
comment
created
freever
username_3
Is there a recommended way to persist state asynchronously, so that the grain can release its caller while persisting? Or is that just generally a bad idea?
comment
created
lpyvvvvvv
username_0
+1
comment
created
rallets
username_4
@username_3 @username_0 it depends on how "important" the grain state is. 
1) If it's not ok for your business to lose "some" state in case of a crash, then you need to persist the grain state as soon it's changed (basically before leaving the grain method), awaiting the WriteStateAsync call to the storage to be able to handle exceptions, as then they are not swallowed. 
2) Instead, if you can get the risk of loosing the grain state in case of errors (silo crash, network failures, storage provider errors, etc), you can use a timer and persist the state only every x seconds.
comment
created
sergeybykov
username_2
Nicely stated, @username_4.
comment