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

appsettingsschema.json is in use by another process #5837

Open
1 task done
JamesNK opened this issue Sep 23, 2024 · 13 comments
Open
1 task done

appsettingsschema.json is in use by another process #5837

JamesNK opened this issue Sep 23, 2024 · 13 comments
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Sep 23, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I see this error inside VS:

Severity	Code	Description	Project	File	Line	Suppression State	Details
Error (active)		The process cannot access the file 'C:\Users\jamesnk\AppData\Local\Temp\appsettingsschema.json' because it is being used by another process.	Keycloak.AppHost, ProxylessEndToEnd.AppHost, TestShop.AppHost	C:\Program Files\Microsoft Visual Studio\2022\IntPreview\MSBuild\Microsoft\VisualStudio\WebTools.Aspire\Microsoft.WebTools.Aspire.targets	47		

image

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version info

No response

Anything else?

No response

@afscrome
Copy link
Contributor

I just saw this too after upgrading a project to 9.0. It stuck around in VS until I restarted VS, and I haven't seen it since.

@joperezr joperezr added the untriaged New issue has not been triaged label Oct 15, 2024
@davidfowl davidfowl removed the bug label Oct 16, 2024
@DamianEdwards
Copy link
Member

I see this a bunch too

@JamesNK
Copy link
Member Author

JamesNK commented Jan 9, 2025

@eerhardt Is this something you know about?

@eerhardt
Copy link
Member

eerhardt commented Jan 9, 2025

I've only seen this in our repo, and not in a normal application. I believe it is coming from VS and not anything we can do in dotnet/aspire.

cc @vijayrkn

@bradygaster bradygaster removed the untriaged New issue has not been triaged label Jan 21, 2025
@bradygaster bradygaster added this to the Backlog milestone Jan 21, 2025
@JakeRadMSFT
Copy link

Image

If anyone hits this again ...

Can you search in Associated Handles for the file path? Please report back what processes have a hold on the file.

@bradygaster bradygaster modified the milestones: Backlog, 9.1 Jan 28, 2025
@danmoseley
Copy link
Member

@bradygaster should this go back to backlog? It seems not actionable, given nobody's posted they've been able to repro.

I bet it's VS and I"ll keep an eye out for it too.

@JamesNK
Copy link
Member Author

JamesNK commented Feb 11, 2025

I searched for the handle after getting this in VS and didn't get any results:

Image

@danmoseley danmoseley modified the milestones: 9.1, Backlog Feb 11, 2025
@danmoseley
Copy link
Member

Moving to backlog as this isn't actionable.

@afscrome
Copy link
Contributor

afscrome commented Feb 13, 2025

I have just seen this in a real aspire app, so I don't think it's limited to this repo.

The error in VS right immediately after I updated my Directory.Packages.props from

    <PackageVersion Include="Aspire.Hosting" Version="9.1.0-preview.1.25111.2" />
    <PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
    <PackageVersion Include="Aspire.Hosting.Redis" Version="9.0.0" />
    <PackageVersion Include="Aspire.Hosting.Testing" Version="9.0.0" />

to

    <PackageVersion Include="Aspire.Hosting" Version="9.1.0-preview.1.25111.2" />
    <PackageVersion Include="Aspire.Hosting.AppHost" Version="9.1.0-preview.1.25111.2" />
    <PackageVersion Include="Aspire.Hosting.Redis" Version="9.1.0-preview.1.25111.2" />
    <PackageVersion Include="Aspire.Hosting.Testing" Version="9.1.0-preview.1.25111.2" />

I've managed to reproduce this a few times (say 2-3 times out of every 20) and managed to capture a procmon trace of this - I can share this privately to help troubleshoot.

Trace was taken with the following filter to keep noise down:
Image

I can see that msbuild.exe is the only process that has tried to access %USERPROFILE%\AppData\Local\Temp\appsettingsschema.json, with the conflict coming with

Image

With the following error showing up in VS:
Image

The process cannot access the file '%USERPROFILE%\AppData\Local\Temp\appsettingsschema.json' because it is being used by another process.

@afscrome
Copy link
Contributor

Based on the error, this seems to be coming from the following in Microsoft.WebTools.Aspire.targets

  <Target Name="GenerateCombinedAppSettingsSchemaTarget"
          DependsOnTargets="GenerateCombinedComponentSchemaTarget"
          Condition=" '@(JsonSchemaSegment)' != '' "
          BeforeTargets="CompileDesignTime"
          Inputs="$(SchemaGenIncrementalBuildInputs);$(JsonSchemaCombinedFilePath)"
          Outputs="$(AppSettingsJsonSchemaCombinedFilePath)">
    <GenerateCombinedAppSettingsSchema
      AppSettingJsonSchemaFilePath="$(AppSettingJsonSchemaLoadFilePath)"
      ComponentJsonSchemaCombinedFilePath="$(JsonSchemaCombinedFilePath)"
      AppSettingsJsonSchemaCombinedFilePath="$(AppSettingsJsonSchemaCombinedFilePath)">
    </GenerateCombinedAppSettingsSchema>
    <Message Text="Generating appsettingsschema" />
  </Target>

Inside Microsoft.WebTools.Aspire.MSBuild.GenerateCombinedAppSettingsSchema.DownloadBaseAppSettingsJsonSchema(), there is the following code

string path = Path.Combine(Path.GetTempPath(), "appsettingsschema.json");
System.IO.File.WriteAllText(path, end);

If multiple projects are building in parallel, and hit this at the same time, one or more will fail. That would suggest this problem is more likely to occur with more projects in the solution, which would explain why we see this regularly within the aspire solution, but not so frequently elsewhere.

This download should either be reworked to be downloaded once per solution rather than once per project, or use a unique filename to avoid conflicts when multiple projects build at once.

I can't find this code in the repo, so I assume this is something Visual Studio specific.

@DamianEdwards
Copy link
Member

So this looks like a "simple" parallel build issue? i.e. if multiple projects are using client integrations that contribute JSON schema and they get built in parallel, you can hit this issue because the file name/path is shared. Shouldn't that file be unique per project?

@DamianEdwards
Copy link
Member

FYI @JakeRadMSFT potential lead on the issue.

@DamianEdwards
Copy link
Member

Ah I see this is the download of the base schema, not the generation of the unique combined schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants