Page MenuHome GnuPG

gpg-agent: Wakes up periodically
Open, WishlistPublic


This bug is forwarded from

"gpg-agent seems to wake up every few seconds, due to select timing out.

gpg-agent should not wake up until either it has something to do, or it
needs to time out a key from memory. The former occurs when select says
it has data to read from its socket, and the latter should sleep until
the target time rather than waking up every couple of seconds."

Event Timeline

It looks like it's due to TIMERTICK_INTERVAL being set to 2 on UNIX platforms so
that it can call handle_tick() every 2 seconds. It looks like handle_tick() just
checks if we've lost our connection to scd, if we've lost our parent, and less
frequently that the socket permissions are correct.

I'm not sure why we would need to check these things every two seconds. Also we
could detect parent death (on linux at least) via PR_SET_PDEATHSIG instead of

Any objections to upping the value?

The ticker is responsible for several house holding tasks and thus we can't
simply disable it or set it too a much higher value. Currently this might be
some easy things but at least the check whether the socket has been taken over
by a second instance (what you call "permission check") is important and can't
be delayed for too long. Given that dirmngr and more import scdaemon also have
such ticker jobs, I doubt that this would lead to any noticable power saving.

Note that some years ago the code was modified to make sure that gpg-agent wakes
up at the full second so that it matches the tickers of other processes.

werner lowered the priority of this task from Normal to Wishlist.Jan 5 2015, 6:19 PM
werner removed a project: Bug Report.
werner added a project: Feature Request.

Well if my reading is correct, the housekeeping happens in handle_tick(). 3
things are happening:

  1. Checks for lost parent. This could be converted to a signal (at least on


  1. Checks for socket permissions. This is checked only every 60 seconds, so we

don't need to wake up every two seconds to check it.

  1. Checks for lost connection to scdaemon... does this have to happen so


dirmngr also seems to wake up often to check the if it's time to do housekeeping
(which it does every 10 minutes). Seems like this could also be improved?

scdaemon does seem harder, but not everyone is using smartcards.

Linux specific things are a no-go unless really needed.

Yes, things could be adjusted to wake up only if reallyneeded but it requires
more code.

What is the problem you try to solve? Do you have any measurements that show
that battery life is improved by changing this?

I submitted these patches on the gnupg-devel mailing list in November 2016:

These are working for me to keep gpg-agent idle on platforms that support
inotify when the user doesn't use scdaemon, and we're now shipping with them
applied in debian unstable.

Note that gpg-agent has been changed years ago to make up at the full second so
that all daemons with a need to wakeup are running at the same time.