Azure / azure-cli

Azure Command-Line Interface
MIT License
4k stars 2.98k forks source link

Fail to deploy .net core function app using az functionapp deployment source config-zip #12710

Open rohank-proarch opened 4 years ago

rohank-proarch commented 4 years ago

az feedback auto-generates most of the information requested below, as of CLI version 2.2.0

Describe the bug

When deploying a .net core function app to Azure Functions on Windows App Service Plan, the deployment fails if it requires changes in app settings.

There's a race condition here:

  1. If the app settings are changed before or after the deployment is initiated, the build fails.
  2. If the app settings are not changed before the deployment is initiated, the build succeeds.

To Reproduce

  1. Create a .Net Core 2.2 Function App in Windows Standard App Service Plan
  2. Prepare a simple function app content, and compress it into a zip file.
  3. Run the command to change the appsettings az functionapp config appsettings set -n $functionAppName -g $resourceGroupName --settings APPINSIGHTS_INSTRUMENTATIONKEY=$instrumentationKey
  4. Run the command az functionapp deployment source config-zip -g $resourceGroupName -n $functionAppName --src
  5. Wait a while and will see the deployment failure error

Expected behavior

The deployment should succeed.

Environment summary

DevOps Hosted Agent: Ubuntu 16.04 Azure CLI Task Shell Type: bash CLI Version: azure-cli 2.2.0

command-modules-nspkg 2.0.3 core 2.2.0 nspkg 3.0.4 telemetry 1.0.4

Extensions: azure-devops 0.17.0

Python location '/opt/az/bin/python3' Extensions directory '/opt/az/azcliextensions'

Python (Linux) 3.6.5 (default, Mar 6 2020, 14:41:35) [GCC 5.4.0 20160609]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

Additional context

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @ahmedelnably, @fabiocav.

yungezz commented 4 years ago

thanks for reporting, routing to appropriate team

anthonychu commented 4 years ago

@rohank-proarch Can you please share with us the error message as well as your app name? Thanks. https://github.com/Azure/azure-functions-host/wiki/Sharing-Your-Function-App-name-privately

rohank-proarch commented 4 years ago

App Name: pa-dw-funcapp-dev.azurewebsites.net Error Message: WARNING: Setting SCM_DO_BUILD_DURING_DEPLOYMENT to false WARNING: Waiting SCM site to be updated with the latest app settings ERROR: The command failed with an unexpected error. Here is the traceback:

ERROR: HTTPSConnectionPool(host='pa-dw-funcapp-dev.scm.azurewebsites.net', port=443): Read timed out. (read timeout=3) Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request httplib_response = conn.getresponse() File "/opt/az/lib/python3.6/http/client.py", line 1331, in getresponse response.begin() File "/opt/az/lib/python3.6/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/opt/az/lib/python3.6/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/opt/az/lib/python3.6/socket.py", line 586, in readinto return self._sock.recv_into(b) File "/opt/az/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 317, in recv_into raise timeout('The read operation timed out') socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/requests/adapters.py", line 449, in send timeout=timeout File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 641, in urlopen _stacktrace=sys.exc_info()[2]) File "/opt/az/lib/python3.6/site-packages/urllib3/util/retry.py", line 368, in increment raise six.reraise(type(error), error, _stacktrace) File "/opt/az/lib/python3.6/site-packages/urllib3/packages/six.py", line 686, in reraise raise value File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 603, in urlopen chunked=chunked) File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 389, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 307, in _raise_timeout raise ReadTimeoutError(self, url, "Read timed out. (read timeout=%s)" % timeout_value) urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pa-dw-funcapp-dev.scm.azurewebsites.net', port=443): Read timed out. (read timeout=3)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 608, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 666, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job six.reraise(sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 636, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 306, in call return self.handler(args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 493, in default_command_handler return op(command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 335, in enable_zip_deploy_functionapp remove_remote_build_app_settings(cmd, resource_group_name, name, slot) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 467, in remove_remote_build_app_settings should_contain=app_settings_should_contain) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 805, in validate_app_settings_in_scm scm_settings = _get_app_settings_from_scm(cmd, resource_group_name, name, slot) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/utils.py", line 62, in call raise exception File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/utils.py", line 58, in call return func(*args, kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 834, in _get_app_settings_from_scm response = requests.get(settings_url, headers=headers, auth=(username, password), timeout=3) File "/opt/az/lib/python3.6/site-packages/requests/api.py", line 75, in get return request('get', url, params=params, kwargs) File "/opt/az/lib/python3.6/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, kwargs) File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, send_kwargs) File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/opt/az/lib/python3.6/site-packages/requests/adapters.py", line 529, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='pa-dw-funcapp-dev.scm.azurewebsites.net', port=443): Read timed out. (read timeout=3)

anthonychu commented 4 years ago

Looks like the app was still restarting after changing the app setting when you started the deployment command. Can you either wait until the restart completes or change the setting after deployment is complete?

rohank-proarch commented 4 years ago

Even if I update the appsettings later after deployment it fails with same error. It started to fail after azure cli was updated to latest version on azure DevOps hosted agent

m1ckr1sk commented 4 years ago

We are also seeing this issue on both v2.2.0 and v2.3.1 when deploying function apps. Last successful deployment was on v2.1.0

ttjackott commented 4 years ago

Also getting this issue when used from our yaml pipeline - very strange.

We actually switched to using Azure CLI for deploying functions from using the AzureFunctionApp@01 task in yaml due to a separate bug - only to find that we're faced with this issue!

ilanRosenbaum commented 4 years ago

I have a very similar issue, is there any consistently working way of deploying Azure functions through the CLI?

shuruev commented 4 years ago

Having the same issue. Also found this SO question which describes similar situation: https://stackoverflow.com/questions/60770160/azure-function-deployment-failed-with-azure-cli-2-2-0-updates-in-azure-pipeline

sonic1981 commented 4 years ago

Reported here as well https://github.com/Azure/azure-cli/issues/13655