Race in GetProjectOptionsFromScript prevents getting referenced packages
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Repro steps:
* call `GetProjectOptionsFromScript`
* start the resulting async as task and pass a cancellation token
* request cancellation on the token source
* call `GetProjectOptionsFromScript` again (probably from a different thread)
* start the task with a new cancellation token
The `GetProjectOptionsFromScript` calls are made using `lock` application to prevent concurrent access.
Calling and cancelling it like this may lead to situation where two scrips closures are calculated concurrently, despite one of them has already been cancelled by the callee. Here're two screenshots for different threads, both made while staying on the same breakpoint:


This leads to a situation where both threads try to write a generated file during the package restore. If the file is locked then the restore fails and results with missing package references are added to `cache` inside `DependencyProvider`, so all later `GetProjectOptionsFromScript` invocations return failed results for the same compiler directive collection.
The build failure details
The cached script closure:

Exception stacktrace:

Contributor guide
Assessment
This issue has not been assessed yet.