-
Notifications
You must be signed in to change notification settings - Fork 31
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
IO monad and stack limit #132
Comments
Hi @haifengkao, Thanks for reporting! Do you have a sample code that reproduces this crash? The fact that contains runIO could be also caused by a problem in the middleware side-effect itself, right? Are you using async code in this middleware? |
Hi @haifengkao , Thanks for sharing the code. I don't have my mac with me currently, so I'm testing on iPad Playgrounds and therefore the diagnostics are not as good as Xcode, of course. But I believe I managed to reproduce the crash with even less code, this for me was enough to crash. var monad: IO<AppAction> = .identity
let MaxCount = 10000000
for i in 0 ..< MaxCount {
let io: IO<AppAction> = .init( {_ in
})
monad = io <> monad // <-- Crashes when this line is present
} Which gave me:
Then I simplified the code to prevent mutation (var), and to check whether that would solve it. It did not, but when the amount of iterations is smaller than 12800, it doesn't crash: let MaxCount = 12800 // 12800 doesn't crash, 12900 crashes
let monad = (0 ..< MaxCount).map { _ in
IO<AppAction>.init {_ in
}
}.reduce(IO<AppAction>.identity, <>) So I'm assuming here this is something with memory in my iPad. Which is strange because the IO instances are not even being called, it's just 13k instances of a tiny class never used. Maybe I can't have good diagnostics on my iPad and I will try properly on my mac, but I wanted to share this meanwhile. |
Yeah, having the 13k instances doesn't crash, because if I remove the "reduce" portion it doesn't crash, so indeed the problem is having 13k nested closures when I use Let me know your thoughts. |
@luizmb My issue is different than the sample code. An action is dispatched from a view. The action is received by a bridge middleware, the bridge middleware sends another action. The action triggered more actions from a side effect middleware. Each action sent will go through the final merged IO monad. In the below images, the stack 37->135, 156->214, 236->296 are the recursive calls produced by the IO monad. The number of recursive calls is proportion to the number of middlewares. Solutions:
|
Hi @haifengkao , I'm currently traveling and couldn't take a look into this, as I don't have access to my Macbook here. Otherwise, I'll have some time only in August to check this again. |
I start to see strange EXEC_BAD_ACCESS with ~500 call stack depth.
The call stack contains a lot of
runIO
I am suspecting the composed IO monad causes this error.
Maybe it's better to save the handlers into an array
The text was updated successfully, but these errors were encountered: