azure-functions-core-tools icon indicating copy to clipboard operation
azure-functions-core-tools copied to clipboard

Implement file locking mechanism for templates/bundle installation

Open aishwaryabh opened this issue 5 months ago • 0 comments

Issue describing the changes in this PR

resolves #4458

When we run dotnet new func, we are expecting the project and item templates to already be installed since they happen right before that command for func new and func init. For some reason, when the tests run in parallel, the templateconfig.json somehow gets messed up when we have multiple instances of func new and func init running on the same machine, so it doesn't find the template for func. If we isolate each test so it isn't run in parallel, we don't see this error anymore.

I've come up with a fix where we install web jobs/isolated templates only if we need it, given that the template isn't already installed.

There also is a race condition when running E2E func new tests where templatesManager.Templates.Result is not set, so fetching the templates fail. This change adds more logs and forces templatesManager.Templates.Result to populate if it hasn't already, since the value is lazily loaded.

The error message that is shown today to the user is:

One or more errors occurred. (Value cannot be null. (Parameter 'value'))

This error message should still show up but with more logs on what exactly it's doing before, in case this error pops up again.

Example of race condition: https://dev.azure.com/azfunc/public/_build/results?buildId=224520&view=logs&j=da439e82-8265-5962-85f8-172d6600cb6f&t=17f2655d-abad-5398-83c4-ac47d6b8119e&l=162

Pull request checklist

  • [x] My changes do not require documentation changes
    • [ ] Otherwise: Documentation issue linked to PR
  • [x] My changes do not need to be backported to a previous version
    • [ ] Otherwise: Backport tracked by issue/PR #issue_or_pr
  • [x] I have added all required tests (Unit tests, E2E tests)

aishwaryabh avatar Jun 20 '25 20:06 aishwaryabh