Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect recursion and check for cancellation in analyser while loops #12916

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

TomEdwardsEnscape
Copy link
Contributor

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) and ResolveOperationSource, 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

Check for cancellation in analyser `while` loops
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 11.0.999-cibuild0039602-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Sep 18, 2023
Merged via the queue into AvaloniaUI:master with commit 5d3a90a Sep 18, 2023
5 checks passed
@TomEdwardsEnscape TomEdwardsEnscape deleted the fixes/analyser-loops branch September 18, 2023 06:55
@MrJul MrJul added the backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch label Sep 30, 2023
grokys pushed a commit that referenced this pull request Oct 2, 2023
Check for cancellation in analyser `while` loops
@grokys grokys added backported-11.0.x and removed backport-candidate-11.0.x Consider this PR for backporting to 11.0 branch labels Oct 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AvaloniaPropertyAnalyzer entering infinite loop in the wild
5 participants