Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.32k stars 433 forks source link

Internet access is required for running azure functions on local machine #3821

Open William1104 opened 1 month ago

William1104 commented 1 month ago

Version

$ func --version
4.0.6280
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"

Description

func start would fail to execute when there is no Internet access. Some developers may have to work in a network without Internet access (or very limited access). It potentially makes azure-functions-core-tools not work..

When the machine has Internet access, we can run the tools locally.

$ func start

Azure Functions Core Tools
Core Tools Version:       4.0.6280 Commit hash: N/A +421f0144b42047aa289ce691dc6db4fc8b6143e6 (64-bit)
Function Runtime Version: 4.834.3.22875

[2024-09-12T16:11:30.915Z] OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.

Functions:

        echo: [GET,POST] http://localhost:7071/api/echo

        hello: [GET,POST] http://localhost:7071/api/hello

        uppercase: [GET,POST] http://localhost:7071/api/uppercase

For detailed output, run func with --verbose flag.
[2024-09-12T16:11:31.526Z] Worker process started and initialized.
[2024-09-12T16:11:35.788Z] Host lock lease acquired by instance ID '000000000000000000000000E7A1833D'.
^C[2024-09-12T16:11:41.082Z] Language Worker Process exited. Pid=6500.
[2024-09-12T16:11:41.082Z] /usr/lib/jvm/java-21-openjdk-amd64/bin/java exited with code 130 (0x82). .

But when we stop the Internet access, the tool would fail to build configuration in an external class. It looks like this process needs to download something from a CDN (functionscdn.azureedge.net:443).

$ func start

Azure Functions Core Tools
Core Tools Version:       4.0.6280 Commit hash: N/A +421f0144b42047aa289ce691dc6db4fc8b6143e6 (64-bit)
Function Runtime Version: 4.834.3.22875

[2024-09-12T16:12:09.804Z] Error building configuration in an external startup class.
[2024-09-12T16:12:09.804Z] Error building configuration in an external startup class. System.Net.Http: Resource temporarily unavailable (functionscdn.azureedge.net:443). System.Net.Sockets: Resource temporarily unavailable.
[2024-09-12T16:12:09.806Z] A host error has occurred during startup operation 'b37baf23-c6f0-476d-a961-41fd6ebcdbf5'.
[2024-09-12T16:12:09.806Z] Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class. System.Net.Http: Resource temporarily unavailable (functionscdn.azureedge.net:443). System.Net.Sockets: Resource temporarily unavailable.
Value cannot be null. (Parameter 'provider')
[2024-09-12T16:12:09.823Z] Host startup operation has been canceled

Steps to reproduce

simply stop the Internet access and then run func start. We should see error following messages:

[2024-09-12T16:12:09.804Z] Error building configuration in an external startup class.
[2024-09-12T16:12:09.804Z] Error building configuration in an external startup class. System.Net.Http: Resource temporarily unavailable (functionscdn.azureedge.net:443). System.Net.Sockets: Resource temporarily unavailable.
[2024-09-12T16:12:09.806Z] A host error has occurred during startup operation 'b37baf23-c6f0-476d-a961-41fd6ebcdbf5'.
[2024-09-12T16:12:09.806Z] Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class. System.Net.Http: Resource temporarily unavailable (functionscdn.azureedge.net:443). System.Net.Sockets: Resource temporarily unavailable.
kshyju commented 1 month ago

@umangsriv Could you investigate this? You can use fiddler to find out what exact URL it is pinging.

May be it's related to https://github.com/Azure/azure-functions-host/issues/9434

umangsriv commented 1 month ago

@umangsriv Could you investigate this? You can use fiddler to find out what exact URL it is pinging.

May be it's related to Azure/azure-functions-host#9434

Sure @kshyju , I'll look into this.

umangsriv commented 1 month ago

Hello @kshyju, I have investigated the issue and performed debugging in both online and offline modes. During my analysis, I identified two suspected URLs:

  1. The first URL appears to be related to issue 9434, which you already mentioned, where an error occurs with ExtensionBundles. However, this URL is only being captured in online mode. image
  2. The second URL is associated with 'devstoreaccount', which is causing errors in both online and offline modes. image

Beyond these, I did not observe and significant issues, if anything else you would suggest I explore or if there are further steps you would recommend, please let me know.

umangsriv commented 1 month ago

Hey @kshyju, could you please provide an update so we can proceed?

umangsriv commented 1 day ago

Hi @kshyju , I wanted to provide an update on the offline mode issue I've been investigating and seek some guidance on the best approach to move forward.

Issue Summary :

The core problem arises when trying to run 'func start' in offline mode, as certain components in the application continue to make network calls to external resources, specifically to 'functionscdn.azureedge.net'.

Example :

A host error has occurred during startup operation '647a2997-d85f-4c99-9bac-49186e155f1d'. [2024-11-04T11:56:26.811Z] Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class. System.Net.Http: No such host is known. (functionscdn.azureedge.net:443). System.Net.Sockets: No such host is known.

Findings

Network Dependencies in multiple components like:

Proposed Solution

Mocking or Bypass Network Dependencies:

I would appreciate any guidance or suggestions on ensuring we address offline mode compatibility comprehensively. Additionally, if there are existing strategies or preferred practices for handling offline mode, insights on those would be very helpful.