Skip to content

Multiple folders output by "pub list-package-dirs" can lead to analysis loop #22555

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

Closed
stereotype441 opened this issue Feb 24, 2015 · 4 comments
Assignees
Labels
devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@stereotype441
Copy link
Member

In circumstances where analysis server's execution of "pub list-package-dirs" yields a mapping from a single package name to multiple source directories (e.g. package "foo" maps to ["/foo1/lib", "/foo2/lib"], there is a risk of creating an analysis loop. The analysis loop occurs as follows:

  • A given file exists in more than one source directory (e.g. files "/foo1/lib/bar.dart" and "/foo2/lib/bar.dart" both exist).
  • The file in the latter directory appears explicitly in an analysis context (e.g. "/foo2" is set as an analysis context, causing "/foo2/lib/bar.dart" to be analyzed).
  • Before analyzing the file, the analysis server converts the explicit file path to a package URI (in accordance with item 1 in issue Change analysis server's handling of package vs file URI's, and add audit rules. #22079). In this example, this yields "package:foo/bar.dart". So it passes a FileBasedSource to the analyzer which points to "package:foo/bar.dart" and "/foo2/lib/bar.dart".
  • Later, the analyzer encounters the URI in another context (e.g. an import statement) and resolves it to the file in the former directory. So in this example, this causes it to create a FileBasedSource which points to "package:foo/bar.dart" and "/foo1/lib/bar.dart".
  • Since FileBasedSource objects are equality compared based on their URI but hashed based on their file, the two FileBasedSource objects may or may not be treated as equivalent by the analysis cache, depending on whether they happen to land in the same hash bucket.
  • If they land in the same hash bucket, then at the end of analysis, when _validateCacheConsistency() runs, it may compare the stored modification timestamp of one file with the actual modification timestamp of the other file, and incorrectly conclude that the file has been changed.
  • If this happens, the failed consistency check will trigger another round of analysis, after which the consistency check will run again (and fail again), triggering a further round of analysis, ad infinitum.

I'm working on a fix for this issue.

@bwilkerson
Copy link
Member

Added this to the 1.9 milestone.
Removed Priority-Unassigned label.
Added Priority-High, Started labels.

@stereotype441
Copy link
Member Author

Partial fix out for review: https://codereview.chromium.org/935453007/

@stereotype441
Copy link
Member Author

Partially fixed in revision 44003.

Keeping the bug open since it could still arise if files are added/deleted after analysis server starts. The reason is that in general, the mapping from URI to file path depends on which files exist in the filesystem, so even after this CL is applied, if files are added/deleted after analysis begins, it's still possible for two FileBasedSource objects to be created that use the same URI but point to different files.

@stereotype441
Copy link
Member Author

As of revision 44026, two FileBasedSource objects that point to different files will never compare equal, so the analysis loop shouldn't happen anymore.

It's still possible for the analysis server to get confused if adding/removing changes which file is meant by a certain URI, but that is a much lower priority problem, and one which will require a different sort of fix. I'll open a separate ticket for it if necessary.


Added Fixed label.

@stereotype441 stereotype441 added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures legacy-area-analyzer Use area-devexp instead. devexp-server Issues related to some aspect of the analysis server labels Feb 25, 2015
@stereotype441 stereotype441 self-assigned this Feb 25, 2015
@stereotype441 stereotype441 added this to the 1.9 milestone Feb 25, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

2 participants