-
Notifications
You must be signed in to change notification settings - Fork 27
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
Cannot dispatch action because state Flow of this FlowReduxStateMachine is not collected yet #688
Comments
Could you share how you are collecting the state machine, specifically based on what you're starting/stopping? |
Here's how I'm starting the state machine:
The state machine is stopped when it reaches the Idle state |
Do you know whether this happens before the start machine starts running or after it's stopped? In either case the safest would be to guard actions being sent based on I was thinking about having an option to relax these checks. What would you expect to happen with an action that is dispatched while the state machine is not running? It could either be dropped or kept internally until the state machine starts. I'm leaning towards the latter since dropping can be achieved with a guard and when the state machine starts it will only handle those actions if it is on the right state. |
This is happening when the state machine is running and haven't reached the idle state yet. To provide more context, here's a simplified version of how our state machine looks like: internal sealed class State {
object Idle : State()
object Start: State()
data class Processing (var subState: State())
object Error: State()
object Success: State()
}
sealed class Event {
object Processing: Event()
object ToError: Event()
object ToSucess : Event()
object GoBack: Event()
}
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
internal class FirstStateMachine(
) : FlowReduxStateMachine<State, Event>(initialState = State.Start)
val currentFlow: FlowReduxStateMachine<State, Event> = this
var nextFlowBuilder: IPostProcessingFlowBuilder? = null
{
init {
spec {
inState<State.Start> {
on {
_, Event.Processing->
state.override { State.Processing}
}
}
inState<State.Processing> {
onEnterStartStateMachine(
stateMachineFactory = {
nextFlowBuilder as FlowReduxStateMachine<State, Event>
},
stateMapper = { state, subState ->
state.override { subState }
},
actionMapper = {
it
}
)
}
inState<State> {
on { _: Event.GoBack, state ->
state.override { State.Idle }
}
}
}
}
val stateFlow: SharedFlow<State> = state.shareIn(
scope = transactionFlowScope,
started = SharingStarted.Eagerly,
replay = 1
)
}
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
internal class SecondStateMachine(
) : IPostProcessingFlowBuilder, FlowReduxStateMachine<State, Event>(initialState)
val currentFlow: FlowReduxStateMachine<State, Event> = this
{
init {
spec {
inState<State.Processing> {
condition({ state ->
state.subState == State.Processing
})
{
on { _: Event.ToError, state ->
state.mutate { copy(subState = State.Error) }
}
on { _: Event.ToSucess, state ->
state.mutate { copy(subState = State.Sucess) }
}
}
}
}
}
the crash happens when we signal events such as Event.ToSucess or Event.ToError to the FirstStateMachine, these crashes are random and only occurs on the release version. Everything works smoothly on the debug version. |
I wanted to highlight that this issue is currently blocking our release, and finding a solution as soon as possible is critical for us. The crashes occur when we signal events such as Event.ToSuccess or Event.ToError to the FirstStateMachine, and these crashes appear to be random, only happening in the release version while the debug version remains unaffected. Is there any additional information or context you could provide that might help us better understand the root cause of this problem? Specifically, any insights on why this might only be occurring in the release version would be greatly appreciated. We are eager to resolve this issue promptly and would greatly value any further guidance or suggestions you can offer. Thank you in advance for your assistance. |
Hi, sorry for the late reply I was out for a bit and then very busy. Is the exception that's causing the crash thrown by |
@sarahborgi I think you should provide the stack trace of crash. |
@gabrielittner @hoc081098
|
Maybe trying to exclude all of In the mean time I'll check again if I can see anything around the stopping of sub state machines that could cause the issue. Also if we can make the error message more helpful in finding out what's going on. Question about your example (just not sure if it's from the simplification or not): The exception has
|
If it's not related to optimization/obfuscation and something like I mentioned in my last comment then 1.2.2 might fix it. |
@sarahborgi Did you have a chance to try out 1.2.2? |
We've integrated the FlowRedux library to manage our app's state, and things have been running smoothly. However, occasionally and unexpectedly, the app crashes and we can see in the traces the "Cannot dispatch action because state Flow of this FlowReduxStateMachine is not collected yet" error.
This error affects various parts of the app. Oddly, it only occurs in the release version, while the debug version remains unaffected.
The text was updated successfully, but these errors were encountered: