Azure / azure-webjobs-sdk-extensions

Azure WebJobs SDK Extensions
MIT License
344 stars 206 forks source link

Cannot run CosmosDB trigger function locally #430

Closed ahmelsayed closed 6 years ago

ahmelsayed commented 6 years ago

From @jdneo on July 4, 2018 9:16

Here is the logs:

[7/4/2018 9:13:33 AM] Reading host configuration file 'D:\work\Java\maven\Azure-Functions-Java-Samples\CosmosDBTrigger\project\target\azure-functions\azure-functions-name-cas-csc8\host.json'
[7/4/2018 9:13:33 AM] Host configuration file read:
[7/4/2018 9:13:33 AM] {}
[7/4/2018 9:13:33 AM] Starting Host (HostId=shechepc-1694341971, InstanceId=13ff8f45-3118-42d9-9dd8-116c7b8272c0, Version=2.0.11888.0, ProcessId=45756, AppDomainId=1, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)
[7/4/2018 9:13:33 AM] 'FUNCTIONS_WORKER_RUNTIME' is specified, only 'java' will be enabled
[7/4/2018 9:13:33 AM] Loading custom extension 'CosmosDBConfiguration'
[7/4/2018 9:13:33 AM] Loaded custom extension: CosmosDBConfiguration from 'D:\work\Java\maven\Azure-Functions-Java-Samples\CosmosDBTrigger\project\target\azure-functions\azure-functions-name-cas-csc8\bin\Microsoft.Azure.WebJobs.Extensions.CosmosDB.dll'
[7/4/2018 9:13:33 AM] Start Process: C:\Program Files\Java\jdk1.8.0_172\bin\java  -jar "C:\Users\sheche\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\java\azure-functions-java-worker.jar" --host 127.0.0.1 --port 53590 --workerId 58a30f94-9465-4412-9513-3a3fe5f82ebc --requestId 954320f2-c0be-4b84-b2ff-cb5f65a0f275 --grpcMaxMessageLength 134217728
[7/4/2018 9:13:33 AM] Generating 1 job function(s)
[7/4/2018 9:13:34 AM] Microsoft Azure Functions Java Runtime [build 1.1.0-beta6]
[7/4/2018 9:13:34 AM] [INFO] {MessageHandler.handle}: Message generated by "StartStream.Builder"
[7/4/2018 9:13:35 AM] Worker initialized
[7/4/2018 9:13:35 AM] "CosmosDb" loaded (ID: bb1ac841-9668-40b9-a274-f215a91831cf, Reflection: "D:\work\Java\maven\Azure-Functions-Java-Samples\CosmosDBTrigger\project\target\azure-functions\azure-functions-name-cas-csc8\cosmos-db-sample-1.0-SNAPSHOT.jar"::"com.azure.functions.samples.CosmosDb.cosmosDBHandler")
[7/4/2018 9:13:36 AM] Found the following functions:
[7/4/2018 9:13:36 AM] Host.Functions.CosmosDb
[7/4/2018 9:13:36 AM]
[7/4/2018 9:13:36 AM] Host initialized (2642ms)
Listening on http://0.0.0.0:7071/
Hit CTRL-C to exit...
[7/4/2018 9:13:36 AM] Host lock lease acquired by instance ID '000000000000000000000000ED91E885'.
[7/4/2018 9:13:39 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:13:39 AM] The listener for function 'Functions.CosmosDb' was unable to start. System.Private.CoreLib: One or more errors occurred. (Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)). Microsoft.Azure.DocumentDB.Core: Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E).
[7/4/2018 9:13:39 AM] The listener for function 'Functions.CosmosDb' was unable to start. System.Private.CoreLib: One or more errors occurred. (Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)). Microsoft.Azure.DocumentDB.Core: Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E).
[7/4/2018 9:13:39 AM]
[7/4/2018 9:13:39 AM] Host started (6395ms)
[7/4/2018 9:13:39 AM] Job host started
[7/4/2018 9:13:39 AM] The following 1 functions are in error:
[7/4/2018 9:13:39 AM] CosmosDb: The listener for function 'Functions.CosmosDb' was unable to start. System.Private.CoreLib: One or more errors occurred. (Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)). Microsoft.Azure.DocumentDB.Core: Unable to load DLL 'Microsoft.Azure.Documents.ServiceInterop.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E).
[7/4/2018 9:13:39 AM]
[7/4/2018 9:13:39 AM]
[7/4/2018 9:13:41 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 1)
[7/4/2018 9:13:41 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:13:41 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:41 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:42 AM]
[7/4/2018 9:13:45 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 2)
[7/4/2018 9:13:45 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:13:45 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:45 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:45 AM]
[7/4/2018 9:13:52 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 3)
[7/4/2018 9:13:52 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:13:52 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:52 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:13:52 AM]
[7/4/2018 9:14:02 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 4)
[7/4/2018 9:14:02 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:14:02 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:02 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:02 AM]
[7/4/2018 9:14:19 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 5)
[7/4/2018 9:14:19 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:14:19 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:19 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:19 AM]
[7/4/2018 9:14:54 AM] Retrying to start listener for function 'Functions.CosmosDb' (Attempt 6)
[7/4/2018 9:14:54 AM] The listener for function 'Functions.CosmosDb' was unable to start.
[7/4/2018 9:14:54 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:54 AM] The listener for function 'Functions.CosmosDb' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Object reference not set to an instance of an object.
[7/4/2018 9:14:54 AM]

Copied from original issue: Azure/azure-functions-core-tools#569

ahmelsayed commented 6 years ago

From @anthonychu on July 4, 2018 22:34

Try running this to get a later version of Microsoft.Azure.DocumentDB.Core which will restore the interop dll properly:

func extensions install -p Microsoft.Azure.DocumentDB.Core -v 2.0.0-preview

More details here: https://github.com/Azure-Samples/functions-serverless-chat-app-tutorial/issues/1

ahmelsayed commented 6 years ago

From @jdneo on July 5, 2018 1:32

@anthonychu Thank you for reaching out. But I'm still getting this error after running the command.

ahmelsayed commented 6 years ago

From @mariomeyrelles on July 5, 2018 12:52

In my case I was running node and not java.

I had to be absolutely sure that the indirect dependency, Microsoft.Azure.Documents.ServiceInterop.dll is present on the \bin folder. Adding Microsoft.Azure.DocumentDB.Core in my case:

Another important thing: I ran this sample using real CosmosDB database and collection. I'm not sure if the emulator is good enough for this kind of scenarios.

The image below shows how things are set on my sample:

image

jdneo commented 6 years ago

Sorry for the confusion. Looks like something is wrong with my environment. Just tried this again and every thing is fine.

@ahmelsayed I think we can close this issue.

JohnReeson commented 6 years ago

Met same error on my side. Init a node function project and new a cosmosdb trigger template.

Got result like @jdneo had. After installing Microsoft.Azure.DocumentDB.Core as @anthonychu suggests, it works.

JohnReeson commented 6 years ago

Use CosmosDB trigger template in VSCode, got new error with cli-beta.37.

Code

module.exports = async function (context, documents) {
    if (!!documents && documents.length > 0) {
        context.log('Document Id: ', documents[0].id);
    }
}

extensions.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <WarningsAsErrors/>
    <DefaultItemExcludes>**</DefaultItemExcludes>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="3.0.1-beta2"/>
    <PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.0"/>
    <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.0.0-preview2"/>
  </ItemGroup>
</Project>

Error message

Microsoft.Azure.Documents.ChangeFeedProcessor: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Documents.Client.ResourceResponse`1<Microsoft.Azure.Documents.Document>> Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentAsync(System.Uri, Microsoft.Azure.Documents.Client.RequestOptions)'.

Complete Cli output

Azure Functions Core Tools (2.0.1-beta.37)
Function Runtime Version: 2.0.12050.0
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\john\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Host.Startup[0]
      Reading host configuration file 'C:\Users\john\Desktop\mycosjs\host.json'
info: Host.Startup[0]
      Host configuration file read:
      {
        "version": "2.0"
      }
[9/2/2018 12:45:05 PM] Initializing Host.
[9/2/2018 12:45:05 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1
[9/2/2018 12:45:06 PM] Starting JobHost
[9/2/2018 12:45:06 PM] Starting Host (HostId=mycat-1685544341, InstanceId=a7d8f7de-947e-4612-a4f9-ede87cd67ebf, Version=2.0.12050.0, ProcessId=41932, AppDomainId=1, Debug=False, FunctionsExtensionVersion=)
[9/2/2018 12:45:06 PM] Starting language worker process:node  --inspect=5858 "C:\Users\john\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\node\dist/src/nodejsWorker.js" --host 127.0.0.1 --port 53221 --workerId f887d6ee-6ed1-4c4a-b11d-e7215f3c2196 --requestId 818eefce-d6c3-492e-a464-081b493d1d91 --grpcMaxMessageLength 134217728
[9/2/2018 12:45:06 PM] node process with Id=35288 started
[9/2/2018 12:45:06 PM] Generating 1 job function(s)
[9/2/2018 12:45:06 PM] Debugger listening on ws://127.0.0.1:5858/be9b8258-23d7-4de0-9bfd-3db6a9cc7665
[9/2/2018 12:45:06 PM] For help see https://nodejs.org/en/docs/inspector
[9/2/2018 12:45:07 PM] Worker f887d6ee-6ed1-4c4a-b11d-e7215f3c2196 connecting on 127.0.0.1:53221 []
[9/2/2018 12:45:09 PM] Found the following functions:
[9/2/2018 12:45:09 PM] Host.Functions.CosmosTriggerJavascript
[9/2/2018 12:45:09 PM]
[9/2/2018 12:45:09 PM] Host initialized (3823ms)
[9/2/2018 12:45:17 PM] The listener for function 'Functions.CosmosTriggerJavascript' was unable to start.
[9/2/2018 12:45:17 PM] The listener for function 'Functions.CosmosTriggerJavascript' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Method not found: 'System.Threading.Tasks.Task`1<Microsoft.Azure.Documents.Client.ResourceResponse`1<Microsoft.Azure.Documents.Document>> Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentAsync(System.Uri, Microsoft.Azure.Documents.Client.RequestOptions)'.
[9/2/2018 12:45:17 PM] Host started (11411ms)
[9/2/2018 12:45:17 PM] Job host started
Hosting environment: Production
Content root path: C:\Users\john\Desktop\mycosjs
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Listening on http://0.0.0.0:7071/
Hit CTRL-C to exit...
[9/2/2018 12:45:19 PM] Retrying to start listener for function 'Functions.CosmosTriggerJavascript' (Attempt 1)
[9/2/2018 12:45:19 PM] The listener for function 'Functions.CosmosTriggerJavascript' was unable to start.
[9/2/2018 12:45:19 PM] The listener for function 'Functions.CosmosTriggerJavascript' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: Host was already initialized.
rybkov commented 6 years ago

Same error with Azure Functions Core Tools (2.0.1-beta.38)

Microsoft.Azure.WebJobs.Extensions.CosmosDB 3.0.1-beta1 - CreateDocumentAsync Microsoft.Azure.WebJobs.Extensions.CosmosDB 3.0.1-beta2 - ReadDocumentAsync

And looks like the issue is in <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.0.0-preview2"/>

After downgrading to 1.9.1 - can run locally.

For Azure Environment: Make sure that FUNCTIONS_EXTENSION_VERSION set to ~2

JohnReeson commented 6 years ago

Confirm no error with latest 3.0.1 CosmosDB extensions. Issue can be closed.

fabiocav commented 6 years ago

Closed as resolved.

@brettsam can you please add the PR/Commit details?

brettsam commented 6 years ago

A duplicate issue is here: https://github.com/Azure/azure-webjobs-sdk-extensions/issues/432

Was fixed with: https://github.com/Azure/azure-webjobs-sdk-extensions/pull/433