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

Support Ctrl+C handling #290

Merged
merged 45 commits into from
Dec 5, 2018
Merged

Support Ctrl+C handling #290

merged 45 commits into from
Dec 5, 2018

Conversation

tmds
Copy link
Member

@tmds tmds commented Nov 5, 2018

An initial attempt at implementing #259.

This adds a Canceled property and Cancel method to the InvocationContext.
This is similar to the RequestAborted and Abort methods on HttpContext.

I'm doing an early PR to get some feedback.

It won't compile on my system, running ./build.sh gives me errors:

/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(10,12): error CS0579: Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(11,12): error CS0579: Duplicate 'System.Reflection.AssemblyConfigurationAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(13,12): error CS0579: Duplicate 'System.Reflection.AssemblyFileVersionAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(14,12): error CS0579: Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(15,12): error CS0579: Duplicate 'System.Reflection.AssemblyProductAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(16,12): error CS0579: Duplicate 'System.Reflection.AssemblyTitleAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]
/home/tmds/repos/System.CommandLine/artifacts/Debug/obj/System.CommandLine/netstandard2.0/System.CommandLine.AssemblyInfo.cs(17,12): error CS0579: Duplicate 'System.Reflection.AssemblyVersionAttribute' attribute [/home/tmds/repos/System.CommandLine/src/System.CommandLine/System.CommandLine.csproj]

@tmds tmds requested a review from jonsequitur November 5, 2018 13:12
@tmds
Copy link
Member Author

tmds commented Nov 13, 2018

I reimplemented this using middleware and added a middleware for AssemblyLoadContext.Default.Unloading (SIGTERM) as well. It looks a lot cleaner now.

@tmds
Copy link
Member Author

tmds commented Nov 13, 2018

I'll look at adding some tests when we settled on a public API.

@jonsequitur
Copy link
Contributor

Tests will be important for helping understand how this is intended to be used and to make sure it's not regressed during refactoring. This is particularly important because we still plan to decompose IConsole.

@tmds
Copy link
Member Author

tmds commented Nov 28, 2018

The lock in InvocationContext was trying to solve a race condition that occurs when AddCancellationHandling is called after Cancel. In that case, there was both a non-cancellable (isCancelling returned false) and a cancelled invocation (invocation with cancelled CancellationToken) happening.
This race is now fixed. Calling AddCancellationHandling is the point where the invocation becomes cancellable.

}
}

private sealed class RemoteExecutionException : XunitException
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the base exception type needs to be Xunit-specific.

@tmds
Copy link
Member Author

tmds commented Dec 4, 2018

Ready to merge!

@tmds
Copy link
Member Author

tmds commented Dec 4, 2018

What do you want to do with wiki_feature_description.md? Shall I remove it from the PR?

@jonsequitur
Copy link
Contributor

If you'd like to remove it from the PR and push it to the wiki, feel free. I'll figure out where to link to it.

@tmds
Copy link
Member Author

tmds commented Dec 5, 2018

I've copied it here: https://github.com/dotnet/System.CommandLine/wiki/Process-termination-handling
You can merge the PR now.

@jonsequitur jonsequitur merged commit aa631e3 into dotnet:master Dec 5, 2018
@tmds
Copy link
Member Author

tmds commented Dec 5, 2018

🎉

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

Successfully merging this pull request may close these issues.

3 participants