Fix race condition in View#render by removing shared mutable state#1499
Open
botandrose wants to merge 1 commit intohotwired:mainfrom
Open
Fix race condition in View#render by removing shared mutable state#1499botandrose wants to merge 1 commit intohotwired:mainfrom
botandrose wants to merge 1 commit intohotwired:mainfrom
Conversation
… to throw an exception.
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.
Hi folks! I'm back with a small concurrency fix.
Problem
The
rendermethod inViewstoresthis.rendererso delegates can mutate it, then accessesthis.renderer.renderMethodafter async operations. A concurrent render can deletethis.renderer, raising:TypeError: can't access property "renderMethod", this.renderer is undefined, resulting in the the first render failing entirely.Root Cause
this.renderer = rendererArenderSnapshot()this.renderer = rendererBfinallyblock runsdelete this.rendererthis.renderer.renderMethod, and boom,undefinedPrognosis
This isn't a critical bug, because it just means a different render wins the race condition than would otherwise. Perhaps its even weirdly desirable as an accidental "optimisation" due to less work being done. But it adds noise to my error reporting with semi-frequent exceptions (a few a day). Mostly, I think shared mutable state in parallel operations is better avoided, if it can be... it's hard to reason about, and could result in a more serious bug in the future that's difficult to track down.
Solution
Remove the
this.renderershared mutable state entirely. Instead of having delegates mutate shared state, haveallowsImmediateRenderreturn the (possibly modified) render function. Any changes to the other properties ofthis.rendererwere not used, so just returning the render function is sufficient to retain the existing behavior.