Detect recursion and check for cancellation in analyser while
loops
#12916
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.
This PR fixes an infinite loop in
AvaloniaPropertyAnalyzer
, as was reported to us by Microsoft in #12864. I haven't been able to reproduce the issue, but by checking for analysis cancellation we can at least ensure that the loop will end when the analyser process requests it to.I also speculatively added a recursion test to both
ResolveOperationTarget
(the reported method) andResolveOperationSource
, since the problem is presumably that the same operations (not symbols, operations) are somehow recursively their own parents or targets.I don't understand how this could happen, but it seems to have at least six times since Avalonia 11 was released. This is a very small number of cases compared to the ~20 000 downloads of each version of Avalonia 11 so far, so I don't intend to spend any more time trying to work out what those six people were doing to enter this infinite loop state.
Lastly, I found a second infinite loop which can be reproduced by assigning an
AvaloniaProperty
field to itself. I added a recursion check to fix this. We just abandon analysis when this happens, as a warning will be emitted about the self-assignment by Microsoft's own analysers.Breaking changes
None
Obsoletions / Deprecations
None
Fixed issues
Fixes #12864