-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "Stack Level Too Deep" error when rendering recursive partials
When rendering recursive partial Action View is trying to generate the view digest infinitly causing a stack level error. Fixes #11340
- Loading branch information
1 parent
a67cc28
commit 09f6fe1
Showing
5 changed files
with
40 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render 'recursion' %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render 'recursion' %> |
This file contains 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
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thedarkone any thread safety concerns here?
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca there's a problem with other threads seeing the "pre-stored"
nil
value, the simplest solution is to have mutex around digest computation (this way if a different thread sees a recursion blockingnil
it defaults to grabbing a mutex to compute the value, this way it is forced to wait for the current thread to successfully compute and replace the placeholdernil
). I also think the code needs to be defensive and have anensure
block that cleans up the@@cache
if theklass.new.digest
call blows up.09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍. Could you open a PR?
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rafaelfranca @thedarkone, I think we've found a bug with this change. Background: Moved off 4.0.0 gem today to 4-0-stable because we have a recursive template being used, ran smack into this bug.
We have a navigation menu that is a 3-level deep tree structure, and uses a recursive template.
When using the cache, via
<% cache template_section do %> ...
in the partial, the following happensFirst-read on server restart: digest-computed, first fetch uses digest in key, all others use false
Second & subsequent reads: all fetches use false value in place of digest.
Under simple testing, and the tests included, the code appears to work because the cache_key with false is still a valid lookup, however it causes breaking problems.
I'll love to offer the solution, but this code it a bit too complex for me to be comfortable I understand the dimensions well enough, but I'm happy to help test any proposed solutions.
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you file an issue so we can track it? Thank you for reporting.
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done #12521
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
09f6fe1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it helps, this is on 2.0.0@p247, running unicorn.