You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fatal RangeError: Maximum call stack size exceeded when combining partial with infinite recursion #5959
The critical piece is partial: if this is removed, for example setting recur = f, then we get a standard RecursionError instead of a fatal pyodide error.
Here, the js_depth/py_depth means how much JS call stack is used for a single Python function on average, and the js_depth is the maximum call stack size in the JS in the browser.
Since the maximum call stack size is around 12,000 in JS, and each Python function call consumes around 6 JS call stack, the Python recursion limit 1000 would not hit the JS call stack maximum normally (1000 * 6 < 12000).
However, in your example, I think using partial makes us consume extra JS call stacks per the function call (I cannot explain exactly why though), which made 1000 python recursion consume more than the 12000 JS call stack size, resulting in the Maximum call stack size exceeded.
We cannot dynamically calculate and update the Python recursion limit, so I think the user should adjust it to prevent such errors.
That makes sense to me. As a bit of motivation: I ran into this while writing application-level code that handles RecursionError (to fall back to an alternative algorithm when infinite recursion is detected). This won't catch the fatal pyodide error. Though I would like it to - If pyodide gave me a way to catch and handle javascript "max call stack size exceeded" errors, I would catch that here as well. I don't know if this can be done in a sane way though.
I'll consider rewriting this code to avoid partial, but it's such an ergonomic util that I wouldn't want to blanket avoid it just in case of running into this.
Just set recursion limit lower? @markshannon recently tried quite hard to make stack checks work on wasm and it didn't work out at all so I'm convinced there's no reasonable way to do it.
Activity
ryanking13 commentedon Oct 20, 2025
Thanks for the report! I can reproduce this in my Chrome (141.0), but not in firefox (144).
Unfortunately, this is not a bug IMO, and the workaround is to reduce the size of the max recursion in Python to, such as 700 using
(by default, we use 1000, which is the default value in CPython too, I think)
The maximum call stack size in JS differs per browser. We regularly measure the stack size in our CI:
Here, the
js_depth/py_depthmeans how much JS call stack is used for a single Python function on average, and thejs_depthis the maximum call stack size in the JS in the browser.Since the maximum call stack size is around 12,000 in JS, and each Python function call consumes around 6 JS call stack, the Python recursion limit 1000 would not hit the JS call stack maximum normally (1000 * 6 < 12000).
However, in your example, I think using
partialmakes us consume extra JS call stacks per the function call (I cannot explain exactly why though), which made 1000 python recursion consume more than the 12000 JS call stack size, resulting in theMaximum call stack size exceeded.We cannot dynamically calculate and update the Python recursion limit, so I think the user should adjust it to prevent such errors.
Liam-DeVoe commentedon Oct 20, 2025
That makes sense to me. As a bit of motivation: I ran into this while writing application-level code that handles
RecursionError(to fall back to an alternative algorithm when infinite recursion is detected). This won't catch the fatal pyodide error. Though I would like it to - If pyodide gave me a way to catch and handle javascript "max call stack size exceeded" errors, I would catch that here as well. I don't know if this can be done in a sane way though.I'll consider rewriting this code to avoid
partial, but it's such an ergonomic util that I wouldn't want to blanket avoid it just in case of running into this.ryanking13 commentedon Oct 21, 2025
That sounds good. Let me think about a way to do it, but probably @hoodmane has some experience with that.
hoodmane commentedon Oct 21, 2025
Just set recursion limit lower? @markshannon recently tried quite hard to make stack checks work on wasm and it didn't work out at all so I'm convinced there's no reasonable way to do it.