How to get reason for ASP.NET Core application shutting down? [duplicate]
Asked Answered
C

1

8

I have containerized my ASP.NET Core 2.2 application into Docker image and then deployed it to Google Kubernetes Engine. Application regularly starts, but every now and then it just randomly shuts down. Log gives no special hints on what is going on, all I get is:

I 2019-07-11T19:36:07.692416088Z Application started. Press Ctrl+C to shut down. 
I 2019-07-11T20:03:59.679718522Z Application is shutting down...

Is there any way I can get reason on why application is shutting down? I know you can register event handler on Shutdown like:

public class Startup
{
    public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime)
    {
        applicationLifetime.ApplicationStopping.Register(OnShutdown);
    }

    private void OnShutdown()
    {
         //this code is called when the application stops
    }
}

But how would I extract reason for application shutdown from there?

Canadianism answered 14/7, 2019 at 21:56 Comment(5)
It might be an obvious suggestion, but what about turning up the log verbosity?Alagez
Do you have logging configured for this and if so how? If you have and still there is no logs, may be the application was shut down externally rather than an exception from the application.Romanesque
it could be server shutting down, if application is sitting ideal, we had that problem in azure, we had to enable azure always on option.Takeo
@KrunalParmar I'm deploying to Google cloud, where it was different issue. Unfortunately I still don't know how to fetch reason for shut down, but at least I guessed what the problem was after understanding more of how GKE works. And turning up log verbosity still doesn't give shutdown reason.Canadianism
@serpent5 U said this but didnt give an example might u do so please.Haygood
C
10

The problem was that by default my ASP.NET Core Web Api project did not handle root path. So / was hit by health check and when it didn't get 200 OK back GKE would should down Kubernetes pod.

Canadianism answered 15/7, 2019 at 14:5 Comment(1)
My specific scenario was similar but slightly different for anyone that has the same. If you have a livenessProbe configured in your dpeloyment.yml make sure that endpoint exists/works. When adding a new API we forgot to add this but it was in deployment.yml (cloned from another service) and this caused k8s to constantly shutdown the service and restart it with no help in the trace logs.Ciliate

© 2022 - 2024 — McMap. All rights reserved.