dotnet / dotnet/fsharp

Race in GetProjectOptionsFromScript prevents getting referenced packages

Open
#12,683 7 comments 2 reactions 0 assignees View on GitHub
Area-FSI Bug Impact-Medium
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:

Screenshot 2022-02-02 at 14 17 37

Screenshot 2022-02-02 at 14 17 16

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:
Screenshot 2022-02-02 at 09 44 52

Exception stacktrace:
Screenshot 2022-02-02 at 09 45 19

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.