Description
Describe the bug
When I add or remove a custom domain programmatically using the Microsoft.Azure.Management.AppService.Fluent
nuget package, the app service restarts. I have confirmed that the app is indeed restarting by creating an empty aspnet core app and only enabling Serilog logging to log when Program.Main()
, Startup.ConfigureServices()
and Startup.Configure()
methods are executed. I found this related issue (MicrosoftDocs/azure-docs#13429) where it is stated by the Microsoft guys that this should not happen.
This is a fragment of my logs after adding or removing a custom domain:
custom hostname added
...
2020-04-06 10:24:47.738 +00:00 [Debug] Hosting shutdown
2020-04-06 10:24:47.766 +00:00 [Debug] Connection id ""0HLUQ2GL99IA2"" disconnecting.
2020-04-06 10:24:47.766 +00:00 [Debug] Connection id ""0HLUQ2GL99IA2"" sending FIN.
2020-04-06 10:24:47.767 +00:00 [Debug] Connection id ""0HLUQ2GL99IA2"" stopped.
2020-04-06 10:24:52.791 +00:00 [Warning] Starting App (Environment: )
2020-04-06 10:24:53.046 +00:00 [Information] Executing Startup.ConfigureServices()
2020-04-06 10:24:53.064 +00:00 [Debug] Hosting starting
2020-04-06 10:24:53.105 +00:00 [Information] Executing Startup.Configure()
2020-04-06 10:24:53.211 +00:00 [Debug] Hosting started
2020-04-06 10:24:53.218 +00:00 [Debug] Loaded hosting startup assembly "TestAppRestart"
2020-04-06 10:24:53.221 +00:00 [Debug] Loaded hosting startup assembly "Microsoft.AspNetCore.Server.IISIntegration"
2020-04-06 10:24:53.439 +00:00 [Debug] Connection id ""0HLUQ2IVF58AG"" started.
2020-04-06 10:24:53.521 +00:00 [Debug] Connection id ""0HLUQ2IVF58AG"" received FIN.
2020-04-06 10:24:53.525 +00:00 [Debug] Connection id ""0HLUQ2IVF58AG"" disconnecting.
2020-04-06 10:24:53.539 +00:00 [Debug] Connection id ""0HLUQ2IVF58AG"" sending FIN.
2020-04-06 10:24:53.542 +00:00 [Debug] Connection id ""0HLUQ2IVF58AH"" started.
2020-04-06 10:24:53.559 +00:00 [Debug] Connection id ""0HLUQ2IVF58AG"" stopped.
...
custom hostname removed
...
2020-04-06 10:26:57.775 +00:00 [Debug] Hosting shutdown
2020-04-06 10:26:57.805 +00:00 [Debug] Connection id ""0HLUQ2IVF58AI"" disconnecting.
2020-04-06 10:26:57.805 +00:00 [Debug] Connection id ""0HLUQ2IVF58AI"" sending FIN.
2020-04-06 10:26:57.806 +00:00 [Debug] Connection id ""0HLUQ2IVF58AI"" stopped.
2020-04-06 10:27:03.285 +00:00 [Warning] Starting App (Environment: )
2020-04-06 10:27:03.540 +00:00 [Information] Executing Startup.ConfigureServices()
2020-04-06 10:27:03.559 +00:00 [Debug] Hosting starting
2020-04-06 10:27:03.606 +00:00 [Information] Executing Startup.Configure()
2020-04-06 10:27:03.787 +00:00 [Debug] Hosting started
2020-04-06 10:27:03.794 +00:00 [Debug] Loaded hosting startup assembly "TestAppRestart"
2020-04-06 10:27:03.795 +00:00 [Debug] Loaded hosting startup assembly "Microsoft.AspNetCore.Server.IISIntegration"
2020-04-06 10:27:04.098 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ0"" started.
2020-04-06 10:27:04.178 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ0"" received FIN.
2020-04-06 10:27:04.191 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ0"" disconnecting.
2020-04-06 10:27:04.219 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ0"" sending FIN.
2020-04-06 10:27:04.238 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ0"" stopped.
2020-04-06 10:27:04.301 +00:00 [Debug] Connection id ""0HLUQ2K6D7LQ1"" started.
...
I've created another issue for the Azure Documentation guys here MicrosoftDocs/azure-docs#51741 (comment) bucause adding/removing custom domains on the Azure portal is causing the exact same behavior. The app stays unresponsive for almost a minute for all other domains bound to it and for the default domain assigned by Azure. I might be wrong but I guess the two issues boil down to the same core problem.
I've tested with both netcore 2.1 and 3.1. I also checked the eventlog.xml
file on my app service storage using the kudu console and I can see the shutdown and startup events firing.
Could you please tell me if this is by design or is it an Azure problem or I'm missing/misinterpreting something? Is there anything I could do to avoid the restart of the app service?
To Reproduce
- Create a new aspnet core app, enable logging and log when
Program.Main()
,Startup.Configure()
andStartup.ConfigureServices()
are called. - Deploy to a new Azure App Service.
- Programmatically add/remove a custom hostname.
- Check logs or
eventlog.xml
file and look forshutdown
.
Code Snippet
This is the code I'm using to add a custom hostname
await webApp.Update()
.DefineHostnameBinding()
.WithThirdPartyDomain("test.example.com")
.WithSubDomain("test.example.com")
.WithDnsRecordType(CustomHostNameDnsRecordType.CName)
.Attach()
.ApplyAsync();
... and to delete it
await webApp
.Update()
.WithoutHostnameBinding("test.example.com")
.ApplyAsync();
Expected behavior
After adding / removing custom hostname, the app service should not restart. If this is by design, the documentation should be clear about it.
Setup (please complete the following information):
- OS: Azure (Windows App Service Plan)
- Version of the Library used: Both 1.13.0 and 1.32.0
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added