Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

IApplicationLifetime ApplicationStopped events not getting called when stopping/restarting Azure web app #846

Closed
rogerdawson opened this issue Aug 31, 2016 · 31 comments
Assignees

Comments

@rogerdawson
Copy link

We've noticed the ApplicationStopped event doesn't seem to get called if you stop or restart a dotnetcore Azure web app (full fat .net 4.6 framework).

Stopping our site in IIS Express doesn't work either (using the system tray stop site option) although the Kestrel server does appear to work (assuming you stop it using ctrl+c).

We did come across the ApplicationStopping issue (#812) which is why we are using ApplicationStopped but it doesn't seem to work. Would I be correct in assuming that selecting stop or restart from the Azure portal is not considered a graceful shutdown?

@muratg muratg added this to the 1.1.0 milestone Sep 7, 2016
@muratg
Copy link

muratg commented Sep 7, 2016

@rogerdawson Could you provide a simple repro app?

@JunTaoLuo can give it a try.

@rogerdawson
Copy link
Author

Hello, I haven't got anything to hand as its embedded in our main app. I'm guessing a standard RTM web app will reproduce the error but the problem will be you'll need a database to log messages to or some other means by which you can detect if the shutdown method has been called. If you haven't got anything like that to hand then I guess I could try and create something. Let me know how you would prefer to proceed. Many Thanks, Roger

@muratg
Copy link

muratg commented Sep 8, 2016

@rogerdawson it would be great if you could share a simple repro app on github for us to investigate. Thanks!

@tx8821
Copy link

tx8821 commented Sep 19, 2016

As said by OP, none of the shutdown events actually fire, when using IIS Express. During debugging with Visual Studio, neither clicking on "Stop Debugging" button in VS, nor right-clicking IIS Express icon in tray and choosing Stop Site/Exit, trigger the event. These thing is just not working! And who runs Kestrel in a console?!...

@rogerdawson
Copy link
Author

Hi,

I'm a bit snowed under at the moment so I can't produce anything
immediately (we can live with the problem for now but I'm registering the
fact there is a bug/issue). As the latest comment states, a console app is
a non-starter so the only way for me to reproduce would be to re-create a
web app that logs to a database or app insights but none of the publish
settings will be relevant as you'll need to publish your own Azure account.
Running a default web app project in IIS Express and breaking pointing the
shutdown event should be all you need to replicate in IIS Express though.

Thanks,

Roger

On 8 September 2016 at 21:58, Murat Girgin [email protected] wrote:

@rogerdawson https://github.com/RogerDawson it would be great if you
could share a simple repro app on github for us to investigate. Thanks!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#846 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABWODUIcsR5GUxUuPN5ZSE_RBDkM08LKks5qoHcGgaJpZM4Jxsey
.

Roger Dawson

GA Digital Ltd

T: +44 (0)1202 619102 <%2B44%20%280%291425%20270970> M: +44
(0)7816 825858 <%2B44%20%280%297885%20957239> F: +44 (0) 808 280
0358

_W: _www.ga-inst.co.uk http://www.ga-inst.co.uk/\ E:
[email protected] [email protected]

This e-mail and any attachment is intended for the named addressee(s) only,
or person authorised to receive it on their behalf. The content may be
privileged and should be treated as confidential and the recipient may not
disclose this message or any attachment to anyone else without
authorisation. Unauthorised use, copying or disclosure may be unlawful. If
this transmission is received in error please notify the sender immediately
and delete this message from your e-mail system. Any view expressed by the
sender of this message or any attachment may be personal and may not
represent the view held by GA Digital Ltd. All electronic transmissions to
and from GA Digital Ltd are recorded, may be monitored and are scanned for
viruses and content. Whilst we maintain virus checks on inbound e-mails we
accept no liability for viruses or other material introduced with this
message.

GA Digital Ltd is registered in England under registered number 06530309
whose registered office address is at Beacon House, 15 Christchurch Rd,
Bournemouth, Dorset, BH1 3LB. VAT Registration Number: GB 929 6678 60.

@guardrex
Copy link
Contributor

@rogerdawson As a workaround (or substitute) did you have any luck trying a subscription to Unloading/ProcessExit?

https://github.com/dotnet/corefx/issues/10012#issuecomment-232436326

@muratg muratg modified the milestones: 1.1.0-preview1, 1.1.0 Oct 11, 2016
@rogerdawson
Copy link
Author

Hi @guardrex , no, I haven't tried that. We've bailed from running our back-end service as a web app as it's just too unreliable - we've had no end of problems with intermittent restarts or the app services (see WEBSITE_LOCAL_CACHE_OPTION for instance which is necessary due to Azure network storage 'glitches'). Web jobs wasn't any better to be honest. We are running as service on a VM now and as well as better reliability we have found performance is almost twice as good (running on a 2-core D2_V2) as opposed to our service plan which was a 4-core S3. Our system is mostly IO bound so we guess this is down to networking. The service is still running as a web app but we now get clean shutdowns (same code, but Windows obviously shuts the service down gracefully so it must be Azure that isn't shutting down the web app gracefully). Thanks for the advice though.

@tomazv
Copy link

tomazv commented Oct 25, 2016

I'm having the same problem.

Here's a repro app: https://github.com/tomazv/applifetime

It writes events to a log and displays the log on each request. It only logs "Application started" and "Before run" but no other events when stopping or restaring the site on Azure.

@muratg muratg removed this from the 1.1.0 milestone Oct 31, 2016
@muratg muratg assigned Tratcher and unassigned Tratcher and JunTaoLuo Oct 31, 2016
@Tratcher
Copy link
Member

See: aspnet/IISIntegration#279 this has been fixed in 1.1 preview of AspNetCoreModule (which won't be deployed to Azure until 1.1 stable releases).

Can you reproduce this issue outside of Azure? If so you can try it with 1.1-preview1 https://blogs.msdn.microsoft.com/webdev/2016/10/25/announcing-asp-net-core-1-1-preview-1/

@Tratcher Tratcher removed their assignment Oct 31, 2016
@tomazv
Copy link

tomazv commented Nov 2, 2016

I have reproduced this issue on IIS (Windows Server 2016) and can confirm it has been fixed in 1.1 preview.

@muratg
Copy link

muratg commented Nov 2, 2016

Awesome!

@muratg muratg closed this as completed Nov 2, 2016
@Plasma
Copy link

Plasma commented May 8, 2017

Hi there. When will 1.1 be deployed to Azure production? Thank you

@muratg
Copy link

muratg commented May 8, 2017

@Plasma 1.1 is already on Azure App Service. Are you having issues deploying?

@Plasma
Copy link

Plasma commented May 8, 2017

@muratg Deploying OK, its just the ApplicationStopping/Stopped events are not firing still. The Started event works.

@muratg
Copy link

muratg commented May 8, 2017

And does it work locally when you're on 1.1?

@Plasma
Copy link

Plasma commented May 8, 2017

What's the test procedure for that, just pressing Stop under VS2017 debugger? I don't run it under IIS its just IIS Express. Cheers.

@muratg
Copy link

muratg commented May 9, 2017

@Plasma You can put a break point on the events you'd like to capture. Or you can log in those events and make sure to see the log lines for the events. IIS vs IIS Express shouldn't be a problem. Also, make sure you're on 1.1 :)

@Plasma
Copy link

Plasma commented May 9, 2017

@muratg I tried putting a breakpoint on a method that also logs to disk when hit, but the breakpoint is not hit when I either press the Stop button in VS2017 (as expected, I'd assume this is a hard terminate), nor when I click 'Stop site' using IIS Express's system tray. I'm using .NET Core 1.1 under 'Target framework'.

Am I supposed to be doing anything special (inherit from a base class, currently I dont inherit from anything for my Startup class, call a method, etc) in order to support these events? ApplicationStarted fires without an issue.

@ghost
Copy link

ghost commented May 12, 2017

I'm having same issue. ApplicationStopped and ApplicationStopping event dosen't fire when run in Azure Web App and IIS Express.
Works when I run it as a console app and hit Ctrl-C.
I'm on net core 1.1

@muratg muratg reopened this May 12, 2017
@muratg
Copy link

muratg commented May 12, 2017

Re-opening based on the most recent comments. @Tratcher could you take a look?

@Tratcher
Copy link
Member

@Plasma @lennynas how are you stopping the site in AWA and IIS Express?

@Plasma
Copy link

Plasma commented May 12, 2017

@Tratcher in Azure it's either the Stop or Restart button or deployment (that must cause a stop somewhere during the update).

For express I tried both "Stop site" under the IIS Express tray icon for the site as well as pressing Stop under VS2017 debugger while debugging.

@wimex
Copy link

wimex commented May 23, 2017

I have also opened an issue about this here.

One thing I'd like to add: in Azure, none of these methods are called even when I'm using the App_Offline.htm file.

@Plasma
Copy link

Plasma commented May 30, 2017

@Tratcher is there anything I can do to assist in helping you debug? Thanks

@Tratcher
Copy link
Member

Tratcher commented Jun 7, 2017

I've confirmed with the IIS Express owners that it does not implement any graceful shutdown mechanics so no shutdown events are expected there.

I'll follow up on the Azure scenario.

@pan-wang
Copy link

I tested on a private stamp. After executing StopWebSite command, ANCM did send ctrl signal to the backend and my test Kestrel app exited as expected. @Plasma, when you stopped your azure site, was there still some on-flying requests?

@Plasma
Copy link

Plasma commented Jun 14, 2017

Hi @pan-wang . I doubt it, as I was testing before any live traffic was hitting the service. Should that matter? Thanks

I could look at preparing an example project if needed.

@Plasma
Copy link

Plasma commented Jun 14, 2017

@pan-wang also worth noting I tested (and expected) the Stopping/Stopped events to take place during scale in/out, stop, start, restart and site deployment requests when updating the code.

@pan-wang
Copy link

pan-wang commented Jun 15, 2017 via email

@halter73
Copy link
Member

It appears that the app services environment doesn't support signalling other processes. I thought that the kudu console handled ctrl+c and the like, but it doesn't: projectkudu/kudu#864

@Tratcher
Copy link
Member

Tratcher commented Jun 22, 2017

Moving this issue to aspnet/AspNetCoreModule#115. The summary is that our signaling mechanics are blocked in azure and we need to design some new ones for 2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests