Skip to content

Defend against parallel access to package assets cache #2159

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@
{1} - Restored version of platform package
{2} - Current version of platform package</comment>
</data>
<data name="UnableToUsePackageAssetsCache" xml:space="preserve">
<value>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</value>
</data>
<data name="AssetsFileNotSet" xml:space="preserve">
<value>The path to the project assets file was not set. Run a NuGet package restore to generate this file.</value>
</data>
</root>
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@
<target state="new">DotnetTool does not support target framework lower than netcoreapp2.1.</target>
<note />
</trans-unit>
<trans-unit id="UnableToUsePackageAssetsCache">
<source>Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</source>
<target state="new">Unable to use package assets cache due to I/O error. This can occur when the same project is built more than once in parallel. Performance may be degraded, but the build result will not be impacted.</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
27 changes: 21 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,21 +348,36 @@ public CacheReader(ResolvePackageAssets task)
{
byte[] settingsHash = task.HashSettings();

if (task.DisablePackageAssetsCache)
{
_reader = CreateReaderFromMemory(task, settingsHash);
if (!task.DisablePackageAssetsCache)
{
// I/O errors can occur here if there are parallel calls to resolve package assets
// for the same project configured with the same intermediate directory. This can
// (for example) happen when design-time builds and real builds overlap.
//
// If there is an I/O error, then we fall back to the same in-memory approach below
// as when DisablePackageAssetsCache is set to true.
try
{
_reader = CreateReaderFromDisk(task, settingsHash);
}
catch (IOException) { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here about why this is swallowing errors similar to what you have in the PR description.

catch (UnauthorizedAccessException) { }
}
else

if (_reader == null)
{
_reader = CreateReaderFromDisk(task, settingsHash);
_reader = CreateReaderFromMemory(task, settingsHash);
}

ReadMetadataStringTable();
}

private static BinaryReader CreateReaderFromMemory(ResolvePackageAssets task, byte[] settingsHash)
{
Debug.Assert(task.DisablePackageAssetsCache);
if (!task.DisablePackageAssetsCache)
{
task.Log.LogMessage(MessageImportance.High, Strings.UnableToUsePackageAssetsCache);
}

var stream = new MemoryStream();
using (var writer = new CacheWriter(task, stream))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void store_nativeonlyassets()
storeDirectory.Should().OnlyHaveFiles(files_on_disk);
}

[CoreMSBuildOnlyFact(Skip="https://github.com/dotnet/sdk/issues/2089")]
[CoreMSBuildOnlyFact]
public void compose_multifile()
{
TestAsset simpleDependenciesAsset = _testAssetsManager
Expand Down