choco icon indicating copy to clipboard operation
choco copied to clipboard

Correctly handle SIGINT / Control+C

Open alexchandel opened this issue 9 years ago • 19 comments

Chocolatey currently prints the following hostile message when interrupted with Control+C:

Exiting chocolatey abnormally. Please manually clean up anything that was not finished.
Please do not ever use Control+C or close the window to exit.

But Control+C is often necessary. For example, for ~~poor~~ various reasons, choco list still lists every package on chocolatey. If you're on VM, or a slow connection, or in a subnet without internet, an accidental choco list can consume substantial time and must be interrupted.

Instead of doing this, why not simply handle the interrupt? On the first Control-C, Homebrew will silently begin to stop its tasks. On the second, it prints the message Just a moment, cleaning up.... And on the third Control-C, it immediately halts its tasks.

### Tasks
- [ ] Handle pressing Ctrl+C while a package is being installed.
- [ ] Handle Ctrl+C while a package is being upgraded.
- [ ] Hand Ctrl+C while a package dependency is being installed to ensure that it doesn't "disappear"

Additional Information

Zendesk Ticket

alexchandel avatar Feb 09 '16 18:02 alexchandel

But Control+C is often necessary. For example, for poor reasons, choco list lists every package on chocolatey.

I take a big issue with the statement "poor reasons". It sounds a bit negative, but I don't see anything on the issue you linked where the reasoning is stated for the current behavior.

It was an inherited choice from the way that NuGet worked, so we emulated the behavior. We've realized that it is incorrect and have defined the boundary where this change will occur. It does take a major version boundary to adjust it for reasons you may not understand if you have not supported a large number of users in a software development project before.

ferventcoder avatar Feb 09 '16 18:02 ferventcoder

For the issue at hand, I often use Control+C, without it corrupting anything. What version of choco are you running?

ferventcoder avatar Feb 09 '16 18:02 ferventcoder

I take a big issue with the statement "poor reasons".

nod. i added -lo in the original chocolatey powershell product to improve it at a time when noone was using choco in the enterprise. Those and many other community driven contributions, whether good or bad (being judged now with 20/20 hindsight) have led to worldwide chocolatey adoption and usage. This has been quite a feat given the usage of open source in the windows world.

Can things be improved, yes but improvements need not be promoted with negativity.

So you know, to compare with other package managers: yum:

yum list will list all packages in all repositories AND all packages on your system. #same accident here yum list installed is required to see just is on your system yum list available etc

apt-cache may handle it more intelligently but these types of features have to be added without breakage. for instance enterprise config management systems rely on functionality in the choco product, that will break if version change is not well coordinated. Those config mgmt systems, in addition need to maintain backward compatibility too w/ choco since everyone doesn't just upgrade big bang overnight.

rismoney avatar Feb 09 '16 19:02 rismoney

Granted. I still hugely favor the brew approach. pacman -Q got it right too.

But for the issue at hand, it's version 0.9.9.11. I usually have no problems with Control+C, except for the most recent time when it blew up on me. I think handling it and attempting to provide orderly termination would greatly improve the user experience.

alexchandel avatar Feb 11 '16 01:02 alexchandel

Yes I agree. The chances of corrupting the xml file are very slight in 0.9.9.11. Handling control+c differently when this file is being edited would be hugely beneficial.

ferventcoder avatar Feb 11 '16 14:02 ferventcoder

@ferventcoder What about handling it everywhere? This would prevent partial/broken installs if it's sent once during installation (permitting Chocolatey to roll back the installation).

alexchandel avatar Feb 15 '16 16:02 alexchandel

:+1: on that.

pyhedgehog avatar Aug 09 '16 12:08 pyhedgehog

It would be very good to also make choco concurrent-safe. At least read-only operations should not break installations. I.e. while I'm installing or upgrading some packages I should be able to use choco outdated.

pyhedgehog avatar Aug 09 '16 12:08 pyhedgehog

It would be very good to also make choco concurrent-safe. At least read-only operations should not break installations. I.e. while I'm installing or upgrading some packages I should be able to use choco outdated.

@pyhedgehog you mean be able to run some commands without pending? The problem here is that non-local search is pretty much the only thing aside from help you could run.

  • choco outdated could provide stale information for something that wasn't installed properly and needs to be removed.
  • choco list -lo would provide information that is out of date.
  • you shouldn't run multiple installs/upgrades at the same time either - that's more a Windows necessity over a Chocolatey need.

We are discussing this at #683

ferventcoder avatar Aug 09 '16 14:08 ferventcoder

Related to #198 / #822

ferventcoder avatar Aug 09 '16 14:08 ferventcoder

that's more a Windows necessity over a Chocolatey need.

Not sure - nothing stops me from downloading several files, also nothing stops me from unpacking several zip files in parallel.

pyhedgehog avatar Aug 09 '16 17:08 pyhedgehog

@pyhedgehog apologies, was referring to native installers

ferventcoder avatar Aug 09 '16 18:08 ferventcoder

"Native" cygwin installer can be run in parallel with any other.

pyhedgehog avatar Aug 09 '16 20:08 pyhedgehog

+1 for Ctrl + C

Odepax avatar Aug 12 '16 14:08 Odepax

Handling SIGINT/Ctrl+C should be done in three stages:

  1. On the first Ctrl+C, chocolatey should immediately begin abandoning what it's trying to do (cancel downloads, cancel file moves, attempted installations) and roll back the partially installed package it's currently working on.
  2. On the second, it should print a message like "Working, just a moment..." to let the user know it hasn't hung.
  3. On the third, it should give up and abort.

alexchandel avatar Sep 27 '16 15:09 alexchandel

@alexchandel I thought we had this discussion here already. However I don't see it on a quick scroll back, so 👍

ferventcoder avatar Sep 27 '16 15:09 ferventcoder

Some reference that could possibly be implemented into the Chocolatey PS helper functions:

https://blogs.technet.microsoft.com/dsheehan/2018/10/27/powershell-taking-control-over-ctrl-c/ and https://stackoverflow.com/questions/1710698/gracefully-stopping-in-powershell

I'd really love to see traction on this issue as I run into https://github.com/chocolatey/choco/issues/1548 from time to time. My requested goal is that when an upgrade is aborted via ctrl-c, that Chocolatey would move the previous package files back from chocolatey\lib-bkp to chocolatey\lib so that the package isn't lost from package management.

I see the "0 - _Triaging" label on this issue, but I believe it should be considered a proper bug.

bcurran3 avatar Jul 27 '19 01:07 bcurran3

This is something I can reliably reproduce with newly installed choco.

choco install miniconda3

see the prompt to install, remember I want -y: ctrl+C choco install -y

now I get that the package is already installed and I should use --force.

Running the same command again actually installs without a fuss.

omry avatar Aug 24 '19 22:08 omry

So this is still not working and not being considered 9 years after first reporting?

Vloeck avatar Oct 12 '25 13:10 Vloeck