2

We have a weird issue when locally debugging an Azure Function V1 with Cosmos DB Trigger. When the app starts, it waits for a couple of minutes and then throws an exception "Service is currently unavailable":

image.png

The same app works just fine when I run it from home. It also runs perfectly when deployed to Azure.

Also, a similar app implemented with Azure Functions V2 works on the problematic machine.

The machines causing the issue are in the corporate network. We use real connection strings, not emulators, with https in it.

It really looks like a client connectivity issue... What can it be and how to resolve it?

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107

1 Answers1

5

The following change in host.json file fixed the issue:

{
  "documentDB": {
    "connectionMode": "Gateway",
    "protocol": "Https"
  }
}

Azure Functions V1 connections to Cosmos DB defaults to Direct Mode, while V2 (which needed to run in any platform as Functions V2 is multi-platform) defaults to Gateway mode. Direct Mode sometimes can have issues in Firewalled environments.

Read more:

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • For those using Azure cosmos db with Asp Core change ConnectionMode = ConnectionMode.Gateway when initation connection in StartUp.cs – Abdi Getachew Sep 14 '20 at 18:57