Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FastKillOnCancelKeyPress not stopping the process. #3935

Merged
merged 6 commits into from
Feb 2, 2018

Conversation

jsukhabut
Copy link

When FastKillOnCancelKeyPress=true State is set to Closing but Stop process never starts.

@jsukhabut
Copy link
Author

Issue #3933

…est" exception is emitted. Adding a validator to give a better error.
@@ -16,6 +17,9 @@ public void ConfigureServices(object configuration, IServiceCollection services)
options.MaxStorageBusyRetries = reader.GetPropertyValue<int>("MaxStorageBusyRetries");
options.ConnectionString = reader.GetPropertyValue<string>("DataConnectionString");
});

services.AddTransient<IConfigurationValidator>(sp => new AzureTableMembershipConfigurationValidator(configuration));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the above IConfigurationValidator change seem orthogonal to this PR - maybe they should be moved into a separate PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am new to this. I thought checking this into my fork would not affect this pull request. This issue is something else. When ClusterId is not set you get a Azure Storage Error "Bad Request". I was had to figure out what was wrong. This check-in was meant for my branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to apologize :)
You can revert those changes in this branch and they'll disappear from here.

If you'd like assistance, let me know.


// force a non-graceful stop
cancellationSource.Cancel();
this.siloLifecycle.OnStop(cancellationSource.Token); // don't wait for it to stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this OnStop call here when OnStop will be called via StopAsync below?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the OnStop after call will get into the mode that just waits for State to Terminate, but nothing signals the lifecycle to stop.

@ReubenBond
Copy link
Member

ReubenBond commented Feb 1, 2018

It seems to me that the correct fix here is to not set SystemStatus directly at all and just call Shutdown() (or Stop(), but my leaning is towards graceful shutdown on Ctrl+C)

EDIT: to clarify, what's happening today is that when someone hits Ctrl+C, the handler sets the SystemStatus to Stopping and then calls Stop() which sees that the SystemStatus is already not Running (and therefore the system is already stopping) and loops forever, waiting for a termination which will never come.

@galvesribeiro
Copy link
Member

I'm having the same issue you described @ReubenBond

@jsukhabut
Copy link
Author

jsukhabut commented Feb 2, 2018

The way I worked around the issue in my console app is to turn FastKillOnCancelKeyPress=false and handle the cancel myself.

Console.CancelKeyPress += Console_CancelKeyPress;

    private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
    {
        Console.WriteLine("*****************Shutdown Started********************");
        cancelToken.Cancel();
        silo.StopAsync(cancelToken.Token);            
    }

Update:

Still not working for me in Kubernetes with this override. Probably due to this line in Orleans.
AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;

@ReubenBond
Copy link
Member

@Jms69 that's how I think it should be done. We should remove the option and allow end-users to configure it themselves.

Particularly since Microsoft.Extension.Hosting will have an abstraction for controlling lifetime of a collection of hosted services.

…Bad Request" exception is emitted. Adding a validator to give a better error."

This reverts commit 4e90eee.
@ReubenBond
Copy link
Member

@Jms69 I submitted a PR against your fork: jsukhabut#1

If it works for you then you can merge it and this PR will automatically update

Terminate gracefully on console cancel key
@jsukhabut
Copy link
Author

jsukhabut commented Feb 2, 2018

I merged the pull request and do some more testing. I am trying to get scale down to work in AKS Kubernetes cluster.

As you mentioned earlier it would be cool if we can provide our own cancel action in case we wanted to do some extra shutdown code:

builder.ConfigurationCancelAction(Action< ISiloHost > action);

@jsukhabut
Copy link
Author

Scale up/down in Kubernetes now works perfectly.

@ReubenBond
Copy link
Member

@Jms69

it would be cool if we can provide our own cancel action in case we wanted to do some extra shutdown code:
builder.ConfigurationCancelAction(Action action);

That's the idea behind the Generic Host Builder which will be released alongside .NET Core 2.1. Once that's available we will work to strip away this functionality and rely on that.

@ReubenBond
Copy link
Member

I'm hoping we can have one more set of eyes on this. I'm happy with it. Please merge if you're happy with it.

@sergeybykov sergeybykov merged commit 4d76acb into dotnet:master Feb 2, 2018
@sergeybykov
Copy link
Contributor

Thank you, @Jms69!

@benjaminpetit
Copy link
Member

From what I understand, here you are doing a clean shutdown, not a fast kill like before (and as the name in the config suggest). I think by default, we should not attempt to do a clean shutdown.

Or at the very least, rename the current config flag

@ReubenBond
Copy link
Member

Good point, the config flag name implies abrupt termination - which I would imagine looks like Environment.FaskKill(). Either way, I'm happy for it to be changed to this.Stop() instead this.Shutdown().

Longer term, Ctrl+C should at least attempt a clean shutdown the first time it's pressed, but this is a concern which we should shift to the generic host.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants