Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.29k stars 429 forks source link

func new not working for JavaScript app #1700

Open jeffhollan opened 4 years ago

jeffhollan commented 4 years ago

did func init on a container and set JavaScript. When I say func new I get this error. I tried passing in flags for language, template, etc. and nothings eems to work

Mac

➜ jehollan-perf-javascript func new Value cannot be null. (Parameter 'value')

➜ jehollan-perf-java func --version 3.0.1975

/cc @ahmedelnably

ahmelsayed commented 4 years ago

can you try CLI_DEBUG=1 func new and share the output? I can't repro this on linux

jeffhollan commented 4 years ago

System.ArgumentNullException: Value cannot be null. (Parameter 'value') at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) at Azure.Functions.Cli.Common.TemplatesManager.GetTemplates() in D:\a\1\s\src\Azure.Functions.Cli\Common\TemplatesManager.cs:line 47 at Azure.Functions.Cli.Actions.LocalActions.CreateFunctionAction.RunAsync() in D:\a\1\s\src\Azure.Functions.Cli\Actions\LocalActions\CreateFunctionAction.cs:line 78 at Azure.Functions.Cli.ConsoleApp.RunAsync[T](String[] args, IContainer container) in D:\a\1\s\src\Azure.Functions.Cli\ConsoleApp.cs:line 66

olillevik commented 4 years ago

I see the same error on a function with worker runtime dotnet. The error disappears after removing these lines from host.json "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" }

Using azure-cli-core-tools version 3.0.2106

daxay-scaletech commented 4 years ago

any updates on this issue, because i am facing that too.

Hazhzeng commented 4 years ago

Hi @soninaren ,

I'm also facing this issue now Value cannot be null. (Parameter 'value'). Using CoreTools 3.0.2534

soninaren commented 4 years ago

@Hazhzeng. This is very likely caused by incomplete download of extension bundle

For Windows:

For Linux:

anthonychu commented 4 years ago

This happens frequently enough and it's not clear how to resolve it. I'd love to see if we can automatically detect this and fix it. #1999

soninaren commented 4 years ago

@anthonychu you are correct about the frequency of the issue. The root cause has been very difficult to detect. That being said we can definitely add some defensive measures to make sure the bundle is fully downloaded before we move ahead.

daxay-scaletech commented 4 years ago

@soninaren I think it is related to slow internet connection. As it stores extension bundle in temp folders of OS system, it will fetch every time on new session of OS. So if there is a slow connection than this issue happens. I already confirmed this.

Temporary solution for Linux users only, needs to do it on every session or when error occurs. For this you have to just download ExtensionBundles only one time. Download it from here:- https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.1.1/Microsoft.Azure.Functions.ExtensionBundle.1.1.1.zip

Now follow this steps:-

  1. Create /tmp/Functions/ExtensionBundles path if not exist, use this command mkdir -p /tmp/Functions/ExtensionBundles
  2. Extract downloaded zip content to folder and rename folder to Microsoft.Azure.Functions.ExtensionBundle
  3. Now copy Microsoft.Azure.Functions.ExtensionBundle to /tmp/Functions/ExtensionBundles folder, use this command cp -R ./Microsoft.Azure.Functions.ExtensionBundle /tmp/Functions/ExtensionBundles/
  4. Now try to run func new or any other command, they will run with ease.

I think this solution apply to windows as well but obviously there must be different path to temp folder and structure.

soninaren commented 4 years ago

@daxay, Core tools is only supposed to download a bundle if a newer version of extension bundle is available. Otherwise it is supposed to use the bundle that is already downloaded to the temp folder. Checking for a newer version of bundle should only need to download a few bytes.

I suspect the combination of the following 2 issues are causing this.

  1. When the core tools tries to download the extension bundle for the first time, the download is only partially successful. Putting the core tools in bad state where it thinks the bundle is downloaded but it isn't.
  2. The core tools could be downloading the bundle every time, even though one is present in the temp folder. So even a single instance of slow connection could put you in a bad state.

I am going to try and optimize bundle download process to do the following:

  1. Perform sha verification to the downloaded bits so we can have a reliable download process.
  2. Use older version of bundle from tmp dirctory in case download fails.
daxay-scaletech commented 4 years ago

@soninaren , I agreed with you about the Core tools behaviour on partially download.

anthonychu commented 4 years ago

@sethjuarez Is running into this as well. On Windows.

❯ func new
System.ArgumentNullException: Value cannot be null. (Parameter 'value')
   at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at Azure.Functions.Cli.Common.TemplatesManager.GetTemplates() in D:\a\1\s\src\Azure.Functions.Cli\Common\TemplatesManager.cs:line 48
   at Azure.Functions.Cli.Actions.LocalActions.CreateFunctionAction.RunAsync() in D:\a\1\s\src\Azure.Functions.Cli\Actions\LocalActions\CreateFunctionAction.cs:line 78
   at Azure.Functions.Cli.ConsoleApp.RunAsync[T](String[] args, IContainer container) in D:\a\1\s\src\Azure.Functions.Cli\ConsoleApp.cs:line 66
anthonychu commented 4 years ago

Got a copy of @sethjuarez's C:\Users\{user}\AppData\Local\Temp\Functions\ExtensionBundles folder (thanks!), it's missing files in the bin folder. It only has the first 5 files alphabetically, which indeed is consistent with an interrupted unzip.

@soninaren Is it possible to write a file at the end of extraction to signal that everything unzipped properly, and use it to decided whether to re-download?

soninaren commented 4 years ago

Writing file at the end of extraction would be tricky. It would be hard to make the operation atomic and we might end up seeing that file anyway. We can introduce a manifest file that lists all the files and their relative paths in the bundle and verify that all files in the bundle are present including the manifest file. We can explicitly trigger bundle download and verification before host start in core tools.

richardweaver commented 4 years ago

I am having this issue in production on Azure. My functions work fine run locally but on Azure I get:

2020-08-10T12:31:41.081 [Error] Executed 'Functions.ImportProduct' (Failed, Id=52d40125-f29c-42af-aceb-c5aa4d0d93b5, Duration=1949ms)
Value cannot be null. (Parameter 'key')

How can I remove the ExtensionsBundle cache on live? Do I need to just do a new build/release and hope for the best?

anthonychu commented 4 years ago

@richardweaver Took a look at the logs on our side. Seeing errors about durableClient is invalid. Can you try it with orchestrationClient instead? durableClient is specific to Durable Functions v2, which will be available in extension bundles v2. It'll be available soon and we'll update our documentation on how to upgrade your app to take advantage of it.

/cc @davidmrdavid

richardweaver commented 4 years ago

@anthonychu Thanks for the pointer. I thought it might be related to the extension bundle issue after some googling around.

However, I removed all the durable functions pieces completely and after deployment it worked fine for a few minutes and then the same error started appearing. Value cannot be null. (Parameter 'key')

/cc @dhardie

anthonychu commented 4 years ago

@richardweaver Can you share the function.json from your functions having the issue?

@mathewc Looks like you might have recently added a null check to address this (https://github.com/Azure/azure-functions-host/pull/6478). Can you share what can cause this problem and any workarounds?

richardweaver commented 4 years ago

@anthonychu Sure:

{
  "bindings": [
    {
      "name": "product",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "importproduct",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "existing",
      "type": "cosmosDB",
      "direction": "in",
      "databaseName": "%DatabaseName%",
      "collectionName": "%ProductsContainer%",
      "connectionStringSetting": "CosmosDBConnectionString",
      "id": "{No}",
      "partitionKey": "product"
    },
    {
      "name": "$return",
      "type": "cosmosDB",
      "direction": "out",
      "databaseName": "%DatabaseName%",
      "collectionName": "%ProductsContainer%",
      "connectionStringSetting": "CosmosDBConnectionString"
    }
  ]
}
richardweaver commented 4 years ago

Just to follow up on this, I can't even create a new function in a fresh, empty project:

C:\Users\weaverr\Projects>func init func-skeleton-3
Use the up/down arrow keys to select a worker runtime:node
Use the up/down arrow keys to select a language:javascript
Writing package.json
Writing .gitignore
Writing host.json
Writing local.settings.json
Writing C:\Users\weaverr\Projects\func-skeleton-3\.vscode\extensions.json

C:\Users\weaverr\Projects>cd func-skeleton-3

C:\Users\weaverr\Projects\func-skeleton-3>func new
Value cannot be null. (Parameter 'value')
Hazhzeng commented 4 years ago

Hi @richardweaver, as Anthony mentioned, to mitigate this issue, you may want to remove the folders in %appdata%/../Local/Temp/Functions. The core tools cache a copy of ExtensionBundles in there. Clearing out the cache will initialize a redownload on the next func command.