Skip to content

[BUG] Memory leak via gpg-agent process #67207

Closed

Description

@OrangeDog

Description
Memory usage of the Salt master's gpg-agent process grows constantly until eventual exhaustion.

pidstat -r -p $(pgrep gpg-agent) 60
12:05:28      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
12:06:28        0   2933164    183.27      0.00  231784   12332   0.21  gpg-agent
12:07:28        0   2933164    148.23      0.00  231784   12460   0.21  gpg-agent
12:08:28        0   2933164      0.00      0.00  231784   12460   0.21  gpg-agent
12:09:28        0   2933164      0.00      0.00  231784   12460   0.21  gpg-agent
12:10:28        0   2933164      6.17      0.00  231784   12460   0.21  gpg-agent
12:11:28        0   2933164    257.37      0.00  231784   12844   0.22  gpg-agent
12:12:28        0   2933164      0.00      0.00  231784   12844   0.22  gpg-agent
12:13:28        0   2933164      0.00      0.00  231784   12844   0.22  gpg-agent
12:14:28        0   2933164     45.28      0.00  231784   12972   0.22  gpg-agent
12:15:28        0   2933164     16.47      0.00  231784   12972   0.22  gpg-agent
12:16:28        0   2933164    131.77      0.00  231784   13228   0.22  gpg-agent
12:17:28        0   2933164     22.63      0.00  231784   13228   0.22  gpg-agent
12:18:28        0   2933164      0.00      0.00  231784   13228   0.22  gpg-agent
12:19:28        0   2933164      0.00      0.00  231784   13228   0.22  gpg-agent
12:20:28        0   2933164     32.97      0.00  231784   13228   0.22  gpg-agent
12:21:28        0   2933164    160.62      0.00  231784   13484   0.23  gpg-agent
12:22:28        0   2933164    260.13      0.00  231784   13740   0.23  gpg-agent
...
17:47:28        0   2933164    162.05      0.00  231784   39340   0.67  gpg-agent
17:48:28        0   2933164    236.98      0.00  231784   39852   0.68  gpg-agent
17:49:28        0   2933164      0.00      0.00  231784   39852   0.68  gpg-agent
17:50:28        0   2933164     22.30      0.00  231784   39852   0.68  gpg-agent
17:51:28        0   2933164     16.18      0.00  231784   39852   0.68  gpg-agent
17:52:28        0   2933164    254.08      0.00  231784   40108   0.68  gpg-agent
17:53:28        0   2933164      0.00      0.00  231784   40108   0.68  gpg-agent
17:54:28        0   2933164      0.00      0.00  231784   40108   0.68  gpg-agent
17:55:28        0   2933164     23.03      0.00  231784   40108   0.68  gpg-agent
17:56:28        0   2933164     23.03      0.00  231784   40108   0.68  gpg-agent
17:57:28        0   2933164    150.62      0.00  231784   40364   0.69  gpg-agent
17:58:28        0   2933164     23.03      0.00  231784   40364   0.69  gpg-agent
17:59:28        0   2933164      0.00      0.00  231784   40364   0.69  gpg-agent
...
09:08:28        0   2933164      0.00      0.00  231784  113964   1.93  gpg-agent
09:09:28        0   2933164     29.30      0.00  231784  114092   1.94  gpg-agent
09:10:28        0   2933164      0.00      0.00  231784  114092   1.94  gpg-agent
09:11:28        0   2933164      0.00      0.00  231784  114092   1.94  gpg-agent
09:12:28        0   2933164     23.02      0.00  231784  114092   1.94  gpg-agent
09:13:28        0   2933164    150.63      0.00  231784  114220   1.94  gpg-agent
09:14:28        0   2933164      0.00      0.00  231784  114220   1.94  gpg-agent
09:15:28        0   2933164      0.00      0.00  231784  114220   1.94  gpg-agent
09:16:28        0   2933164     39.77      0.00  231784  114476   1.94  gpg-agent
09:17:28        0   2933164    244.78      0.00  231784  114604   1.95  gpg-agent
09:18:28        0   2933164     75.28      0.00  231784  114860   1.95  gpg-agent
09:19:28        0   2933164     75.33      0.00  231784  114860   1.95  gpg-agent
09:20:28        0   2933164     23.02      0.00  231784  114860   1.95  gpg-agent
09:21:28        0   2933164     16.73      0.00  231784  114860   1.95  gpg-agent
09:22:28        0   2933164    108.80      0.00  231784  115116   1.95  gpg-agent
09:23:28        0   2933164    152.75      0.00  231784  115372   1.96  gpg-agent
... days later ...
09:59:09        0   2933164     46.73      0.10  960876  702124  11.92  gpg-agent
10:00:09        0   2933164      0.00      0.00  960876  701996  11.92  gpg-agent
10:01:09        0   2933164    281.82      0.05  960876  703276  11.94  gpg-agent
10:02:09        0   2933164      7.87      0.05  960876  703532  11.94  gpg-agent
10:03:09        0   2933164    327.27     71.05  960876  703916  11.95  gpg-agent
10:04:09        0   2933164     67.12      0.10  960876  703020  11.93  gpg-agent
10:05:09        0   2933164      0.00      0.00  960876  703020  11.93  gpg-agent
10:06:09        0   2933164      0.00      0.00  960876  703020  11.93  gpg-agent
10:07:09        0   2933164     53.40      0.10  960876  703660  11.94  gpg-agent
10:08:09        0   2933164    177.02      0.00  960876  703660  11.94  gpg-agent
10:09:09        0   2933164     15.62      0.00  960876  702892  11.93  gpg-agent
10:10:09        0   2933164     19.72      0.05  960876  703916  11.95  gpg-agent
10:11:09        0   2933164    174.45      0.05  960876  704172  11.95  gpg-agent

Setup
git_pillar is configured, with git_pillar_update_interval: 300
Various pillars use the gpg renderer. All other related settings are default.

Steps to Reproduce the behavior
Run the system with some encrypted pillar data and a handful of minions running highstates every 15 minutes.

Expected behavior
Memory usage should plateau once everything has started up.

Versions Report

salt --versions-report
Salt Version:
          Salt: 3006.9

Python Version:
        Python: 3.10.14 (main, Jun 26 2024, 11:44:37) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.17.1
      cherrypy: unknown
  cryptography: 42.0.5
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.4
       libgit2: 1.7.2
  looseversion: 1.0.2
      M2Crypto: 0.38.0
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: 1.14.1
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.17.0
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: ubuntu 24.04.1 noble
        locale: utf-8
       machine: x86_64
       release: 6.8.0-51-generic
        system: Linux
       version: Ubuntu 24.04.1 noble
Package: gpg-agent
Version: 2.4.4-2ubuntu17

Activity

  1. added
    bug
    on Jan 28, 2025
  2. OrangeDog commented on Feb 17, 2025

    @OrangeDog
    ContributorAuthor

    I currently have to restart the salt-master ~every six days to avoid unexpected OOM killings.

  3. self-assigned this
    on Feb 19, 2025
  4. added this to the Sulfur v3006.10 milestone on Feb 19, 2025
  5. dmurphy18 commented on Feb 19, 2025

    @dmurphy18
    Contributor

    Wondering if anyway related to this master memory leak #67050, understand this is 3006.9, but could be in both versions of salt-master

  6. added
    cannot-reproduce
    on Mar 13, 2025
  7. dmurphy18 commented on Mar 13, 2025

    @dmurphy18
    Contributor

    @OrangeDog Wondering about if it is gpg-agent or Salt that is at fault, testing it now. But while I wait, thinking about if it is due to gpg-agent and how to prove that, or some case where Salt is not releasing something getting used in gpg-agent and hence it is holding on to memory. Also have top and htop running apart from the command that you are using.

    Well ran overnight with a bash script running a highstate on the minion every two seconds with an encrypted pillar, and no increase in memory usage, pidstat for gpg-agent has remained at %MEM 0.09, HTOP is rounding up to %MEM 0.1.

    Using a version of Salt branch 3006.x which should be close to what is going to be released very soon, running on updated Ubuntu 24.04.02, was using the default 60 for git_pillar_update_interval, retrying with it set to 300 but don't expect that to change much.

    Any other ideas on way to reproduce, I am doing the following, master and minion on same VM

    david@david-XPS-15-9570:~/dev/fix_67810/test_srv$ cat pillar/top.sls 
    base:
      '*':
        - base
    david@david-XPS-15-9570:~/dev/fix_67810/test_srv$ cat pillar/base.sls
    #!yaml|gpg
    
    encrypted:
      file: |
        -----BEGIN PGP MESSAGE-----
        hF4DAAvGSgfDe8QSAQdA7XIfRHVIJZqVQVaJSavrovY1o6+Z2w6mzYse8xvGvWkw
        TuOocODKfB7iDUVv5uxwo/Qa1RXrHBeNUmi69TbbcW2FuSHY+s0/MuD2KK/3AmO4
        1FYBCQIQwfDQgnVgxDAMAW0sU+Ie6ogYywpYLagJoe8DVkWie7++earscySsETPr
        hwW5ae003XfsxTDYPo83c8YSz1yxWQ/IqkL1ZoGoDLXRsXMUwAKLvg==
        =1Q8K
        -----END PGP MESSAGE-----
    david@david-XPS-15-9570:~/dev/fix_67810/test_srv$ cat salt/
    dgm_state.sls   test_state.sls  top.sls         
    david@david-XPS-15-9570:~/dev/fix_67810/test_srv$ cat salt/dgm_state.sls 
    /tmp/encrypted_file.txt:
      file.managed:
        - contents_pillar: encrypted:file
    
    david@david-XPS-15-9570:~/dev/fix_67810/test_srv/salt$ cat t1
    #!/usr/bin/bash
    
    for idx in {1..100000}; do
        sleep 2
        echo "loop $idx"
        salt tu2404 state.highstate
    done
    david@david-XPS-15-9570:~/dev/fix_67810/test_srv/salt$
    

    Trying to see if I can repeat the problem using my tests on 3006.9

  8. dmurphy18 commented on Mar 20, 2025

    @dmurphy18
    Contributor

    @OrangeDog Can you retry on the just released Salt 3006.10

  9. OrangeDog commented on Mar 21, 2025

    @OrangeDog
    ContributorAuthor

    Well that's vexing. I don't have many reproduction ideas.

    It's still happening with 3006.10:

                  UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
    14:25:20        0   1189132      6.67      0.00  371052  188972   3.21  gpg-agent
    14:26:20        0   1189132     25.12      0.05  371052  190380   3.23  gpg-agent
    14:27:20        0   1189132      0.00      0.00  371052  190380   3.23  gpg-agent
    14:28:20        0   1189132    418.12      0.00  371052  190764   3.24  gpg-agent
    14:29:20        0   1189132    142.32      0.00  371052  191148   3.24  gpg-agent
    14:30:20        0   1189132      0.00      0.00  371052  190892   3.24  gpg-agent
    

    Is there any way to get it to be used in any different way (e.g. not left running after use)?

    UID          PID    PPID  C STIME TTY          TIME CMD
    root     1189132       1  3 Mar20 ?        00:59:36 gpg-agent --homedir /etc/salt/gpgkeys --use-standard-socket --daemon
    

    And in case it's at all relevant:

    # ls -la /etc/salt/gpgkeys/
    total 100
    drwx------ 3 root root  4096 Mar 21 14:39 .
    drwxr-xr-x 7 root root  4096 Mar 20 06:00 ..
    -rw-r--r-- 1 root root    25 Jul 19  2021 .#lk0x000055dfb242a550.salt-vm.1042076
    -rw-r--r-- 1 root root    25 Nov 17  2020 .#lk0x000055fb8acf8550.salt-vm.3663457
    -rw-r--r-- 1 root root    25 Feb 23  2021 .#lk0x00005601f7ccff40.salt-vm.2168209
    -rw-r--r-- 1 root root    25 Feb 23  2021 .#lk0x00005638df858f20.salt-vm.2168109
    -rw-r--r-- 1 root root    25 Feb 17 10:30 .#lk0x00005744f15f3180.salt-vm.3546249
    -rw-r--r-- 1 root root    25 Feb 26 15:35 .#lk0x00005a0cdb040180.salt-vm.785560
    -rw-r--r-- 1 root root    25 Feb 20 10:36 .#lk0x0000638d5a73c180.salt-vm.1165803
    drwx------ 2 root root  4096 Jan 11  2019 private-keys-v1.d
    -rw-r--r-- 1 root root  1982 Feb 23  2021 pubring.kbx
    -rw-r--r-- 1 root root  1988 Feb 23  2021 pubring.kbx~
    srwx------ 1 root root     0 Mar 20 06:01 S.gpg-agent
    srwx------ 1 root root     0 Mar 20 06:01 S.gpg-agent.browser
    srwx------ 1 root root     0 Mar 20 06:01 S.gpg-agent.extra
    srwx------ 1 root root     0 Mar 20 06:01 S.gpg-agent.ssh
    -rw-r--r-- 1 root root 49152 Feb 23  2021 tofu.db
    -rw------- 1 root root  1200 Feb 23  2021 trustdb.gpg
    
  10. dmurphy18 commented on Mar 21, 2025

    @dmurphy18
    Contributor

    So this could be the interaction of many minions with a master, but still no idea as to whether it is the salt-minion or gpg-agent that is having the leak, or if the minion is not closing some resource from the gpg-agent when it is done, the old ref count not going to zero style of issue.

    Could also be the way I am accessing the encrypted pillar is different and not incurring the hit.

    Can you show the way you are accessing the encrypted pillar file, event pseudo state cleaned up example, so that I can try duplicating exact conditions.

    Given the infrastructure changes under Broadcom, having multiple VMs with salt-minions will be difficult to duplicate, but will try that if my current environment with your example fails to duplicate the problem.

  11. OrangeDog commented on Mar 23, 2025

    @OrangeDog
    ContributorAuthor

    Surely the minions have nothing to do with it, other than triggering refreshes? Pillars are rendered on the master, which is where any gpg interaction would happen.

    Unless it has nothing to do with pillars, and Salt calls gpg for something else?

    Most of my pillar access is via pillar.get in map.jinja templates. There are a few pillar['key']s in sls files and file.managed templates too.

  12. 20 remaining items

  13. OrangeDog commented on Jun 30, 2026

    @OrangeDog
    ContributorAuthor

    I've upgraded from .20 to .26 and this looks like it's been fixed.
    The RSS of gpg-agent has not gone above 3404 after several hours.
    Itself had been upgraded as patches were released, and is now 2.4.4-2ubuntu17.4.

  14. dwoz commented on Jul 1, 2026

    @dwoz
    Contributor

    fixed in 3006.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcannot-reproducememory-leak

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions