question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding/Removing custom domain restarts the app service

See original GitHub issue

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 (https://github.com/MicrosoftDocs/azure-docs/issues/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 https://github.com/MicrosoftDocs/azure-docs/issues/51741#issuecomment-609515315 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

  1. Create a new aspnet core app, enable logging and log when Program.Main(), Startup.Configure() and Startup.ConfigureServices() are called.
  2. Deploy to a new Azure App Service.
  3. Programmatically add/remove a custom hostname.
  4. Check logs or eventlog.xml file and look for shutdown.

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
eydelriverocommented, Jul 16, 2020

Hi @rickpmartin . I followed the indications in this SO answer https://stackoverflow.com/questions/60743863/azure-web-app-random-restart-can-anyone-expand-on-this-recommendation, and added the WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG configuration with value 1 to the app service in the Azure portal. This is the only way so far I have prevented the app service from restarting after adding /removing custom domain bindings.

image

There might be side effect though. After adding this stetting, I started to see this warning in my logs:

Level:Warning
Message:Connection processing ended abnormally.
SourceContext:Microsoft.AspNetCore.Server.Kestrel
Exception:
Message:The connection was aborted
StackTrace:   at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()

I’m not sure whether or not this is related with the new setting. Apart from that, I haven’t seen any effects on the normal execution of the app.

1reaction
rickpmartincommented, Jul 17, 2020

Worked for me too, thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add custom domain on Azure without application restart?
Few months ago Azure started restarting applications when change occurs in custom domains. This behavior is, of course, quite bothersome as, ...
Read more >
App Domain restarted when adding new files into wwwroot ...
I have an App Service deployed on three different regions (exact same code). My services needs to syncup some files at run-time and...
Read more >
Azure App Service: Custom Domain for Virtual Application
As you've discovered, virtual applications can't be bound to a custom domain. Reason being is because the domain is bound to the worker...
Read more >
Map existing custom DNS name - Azure App Service
Learn how to add an existing custom DNS domain name (vanity domain) to a web app, mobile app back end, or API app...
Read more >
Stop and start the Application Server
Find the service named PaperCut Application Server. Right-click the service. Select the option you want to perform (for example, Stop/Start/Restart).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found