Repository navigation
fix: count closure calls toward recursion_limit so infinite closure recursion errors instead of crashing - #19229
Merged
Conversation
… recursion errors instead of crashing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A closure that calls itself crashes Nushell:
$env.config.recursion_limit(default 50) exists for this, but only custom command calls added toStack::recursion_count. A closure call copied the caller's count unchanged, so the check at the top ofeval_ir_blocknever fired for closures. The recursion ran until the Rust stack overflowed and the process aborted.User-facing changes (Release notes)
Fixed crashes from infinite closure recursion
Fixed a crash when a closure recursed without end. Closure calls (
do,each,where, hooks, and so on) now count toward$env.config.recursion_limit, just like custom command calls. Infinite closure recursion now raises anu::shell::recursion_limit_reachederror instead of crashing Nushell with a stack overflow.For example,
let M = {|x| do $x $x}; do $M $Mnow produces:A recursive custom command that calls itself from inside a closure now uses two levels of the limit per recursion. With the default limit of 50, it stops at 25 levels instead of 50. Raise
$env.config.recursion_limitin your config file if you need deeper recursion.Additional notes