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

(git.install) gpg-agent.exe not killed before git package upgrade #1451

Closed
medianick opened this issue Mar 30, 2020 · 16 comments
Closed

(git.install) gpg-agent.exe not killed before git package upgrade #1451

medianick opened this issue Mar 30, 2020 · 16 comments
Assignees
Labels

Comments

@medianick
Copy link

Expected Behavior

When upgrading the git package, it installs successfully even if GPG commit signing had previously been in use.

Current Behavior

If GPG commit signing had been in use (such that gpg-agent.exe is running at the time of the choco upgrade or cup command), the git installer will be unable to upgrade it, and the git (and git.install) upgrade will fail.

Possible Solution

taskkill /im gpg-agent.exe /f prior to starting the git upgrade

Steps to Reproduce (for bugs)

  1. Enable commit signing
  2. Within your current Windows session, sign a commit (which will launch the gpg-agent.exe task)
  3. Run choco upgrade git

Context

Unless I've restarted Windows since the last time I signed a commit, the git upgrade via Chocolatey always fails.

Your Environment

  • Package: recent Git packages (e.g., 2.25.1 to 2.26.0)
  • OS: Windows 10
  • Chocolatey version: 0.10.15
@medianick medianick changed the title (git.install) gpg-agent.exe not killed before git package install (git.install) gpg-agent.exe not killed before git package upgrade Mar 30, 2020
@majkinetor majkinetor added the Bug label Apr 1, 2020
@majkinetor
Copy link
Contributor

It could be argued thaat this is upstream problem. Native installer should do so.

@AdmiringWorm AdmiringWorm self-assigned this Apr 1, 2020
@AdmiringWorm
Copy link
Member

Can't say that I have seen this error myself, as the git installer kills the gpg-agent.exe whenever I upgrade git through chocolatey.

I assume we could implement some way to stop the process during upgrade/uninstalls though just to be safe.

I will look into it as soon as I can do that, or if someone is interested feel free to open a PR for it instead.

@majkinetor
Copy link
Contributor

Maybe it can't kill it on specific machine due to rights.

@AdmiringWorm
Copy link
Member

Maybe. But there should be no harm as far as I can see to add stopping the process in a chocolateyBeforeModify.ps1 script anyways.

@AdmiringWorm
Copy link
Member

The code necessary to resolve this has been added to the install package, and will be available for any future versions of the git/git.install package.

@medianick
Copy link
Author

medianick commented Apr 19, 2020

@AdmiringWorm this looks not to have made it into the git 2.26.1 release from a few days ago? At any rate, a cup all with git and git.install 2.26.0 installed (which should have upgraded to 2.26.1) failed, with

Installing 64-bit git.install...
ERROR: Running ["C:\ProgramData\chocolatey\lib\git.install\tools\Git-2.26.1-64-bit.exe" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOCANCEL /SP- /LOG /COMPONENTS="icons,assoc,assoc_sh,ext,ext\shellhere,ext\guihere,gitlfs,icons\quicklaunch" ] was not successful. Exit code was '1'. See log for possible error messages.
The upgrade of git.install was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\git.install\tools\chocolateyInstall.ps1'.
 See log for details.

I grabbed the first Get-Process ... and Stop-Process ... (without -Force) PowerShell commands from 7dd16c2 and ran them, to verify that they stopped the gpg-agent process, then was able to do a choco install git -y --force (forcing because the upgrade had failed but it still thought it was installed), and that worked.

Maybe this wasn't expected to have made it into the 2.26.1 release but I thought I should note it here just in case it was.

@AdmiringWorm
Copy link
Member

@medianick I guess I should have been a little clearer in my last comment.

It did make it into the 2.26.1 release, however, as I had already mentioned it was added to the chocolateyBeforeModify.ps1 script.
This script is run from the already installed package version, not from the package version you are upgrading to.

So in the end, the code was added, but won't be run until a version after the package version the code was added to have been installed.

@medianick
Copy link
Author

Got it, thank you for the clarification!

@medianick
Copy link
Author

The same error happened with the upgrade from 2.26.1 to 2.26.2; I had to taskkill gpg-agent.exe once again, then install git with --force to fix the installation. Is there a place I can locally confirm whether this corrected script is already in place, for the next upgrade after 2.26.2?

@AdmiringWorm
Copy link
Member

@medianick the file should be located at %ChocolateyInstall%\lib\git.install\tools and be called chocolateyBeforeModify.ps1. This file should run before upgrading and before uninstalling a package.

During your upgrade, you should also have gotten at least one warning mentioning it will try to stop the GPG Agent.
If you didn't, then it would mean that the script wasn't finding any process matching gpg-agent*.

@medianick
Copy link
Author

@AdmiringWorm indeed the expected .ps1 file is in that location, so I'm not sure what the problem could be. I just signed a new commit (which launched the expected gpg-agent process) and have verified in an elevated PowerShell that running the chocolateyBeforeModify.ps1 file there does indeed output the expected warning messages (and stops the process), and rerunning it (with the process now stopped) does not output anything, again as expected.

I can wait until the next git upgrade to try once more, and will capture the output then.

@viceice
Copy link

viceice commented Nov 5, 2021

image

gpg-agent isn't killed for me, any idea why? Upgraded from v2.33.0.2 to v2.33.1.

After manual stopping with gpgconf --kill gpg-agent it worked, also manual killing via stop-process in powershell works. 🤔

@medianick
Copy link
Author

Yeah, I meant to come back to this ticket and follow up; gpg-agent.exe is still not automatically stopped for me when I upgrade git via Chocolatey, so it's still exactly as I first described it.

@brogers5
Copy link
Contributor

brogers5 commented Jun 19, 2022

Just ran into this problem again with v2.36.1 and figured I'd dig into what's going on.

From what I'm seeing, when the upgrade is driven via the metapackage (i.e. choco upgrade git), this skips over git.install's chocolateyBeforeModify.ps1 entirely (verified under debug mode), but it executes correctly when driven via the installer package (i.e. choco upgrade git.install). I'm thinking the solution would be to extract the gpg-agent termination into a helper function, then call it from both chocolateyBeforeModify.ps1 (to accommodate the uninstall case) and chocolateyInstall.ps1 as a pre-install step (similarly to how ssh-agent is handled) to accommodate both possible upgrade scenarios.

@TheCakeIsNaOH
Copy link
Member

@brogers5 it looks like this may be caused by this issue: chocolatey/choco#1092

Can you open an enhancement discussion? Since this issue is already closed and is for the beforemodify script.

@brogers5
Copy link
Contributor

@TheCakeIsNaOH Follow-up discussion opened here:
#1924

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

No branches or pull requests

6 participants