2023-08-28 09:54:19 |
Michael Vogt |
description |
It looks like snapd is leaking snaps when refresh-app-awareness is in use. This got reported in the forum in https://forum.snapcraft.io/t/snaps-autoclean-disable-cache-seeds-for-juju-ci-cd/36363 and indeed on my systems:
```
$ ls /var/lib/snapd/snaps/firefox*
/var/lib/snapd/snaps/firefox_2387.snap /var/lib/snapd/snaps/firefox_2531.snap
/var/lib/snapd/snaps/firefox_2391.snap /var/lib/snapd/snaps/firefox_2559.snap
/var/lib/snapd/snaps/firefox_2393.snap /var/lib/snapd/snaps/firefox_2937.snap
/var/lib/snapd/snaps/firefox_2417.snap
```
I looked at the code and it seems the issue is the following:
1. When the refresh starts the soft check that firefox is running reports it is not (this can happen e.g. on startup of the computer when snapd checks for auto-refreshes and the user has not clicked on "firefox" yet)
2. user clicks on firefox, it is now running while the snap is downloading
3. the code path in handlers.go:doPreDownloadSnap() or handlers.go:doUnlinkCurrentSnap() are hit, here firefox is now busy and asyncRefreshOnSnapClose() is called
4. however if firefox is not closed and asyncRefreshOnSnapClose() / continueRefreshOnSnapClose() is aborted it seems no cleanup of the download is happening |
It looks like snapd is leaking snaps when refresh-app-awareness is in use. This got reported in the forum in https://forum.snapcraft.io/t/snaps-autoclean-disable-cache-seeds-for-juju-ci-cd/36363 and indeed on my systems there are many more snaps for firefox than the default retain value of 2:
```
$ ls /var/lib/snapd/snaps/firefox*
/var/lib/snapd/snaps/firefox_2387.snap /var/lib/snapd/snaps/firefox_2531.snap
/var/lib/snapd/snaps/firefox_2391.snap /var/lib/snapd/snaps/firefox_2559.snap
/var/lib/snapd/snaps/firefox_2393.snap /var/lib/snapd/snaps/firefox_2937.snap
/var/lib/snapd/snaps/firefox_2417.snap
```
I looked at the code and it seems the issue is the following:
1. When the refresh starts the soft check that firefox is running reports it is not (this can happen e.g. on startup of the computer when snapd checks for auto-refreshes and the user has not clicked on "firefox" yet)
2. user clicks on firefox, it is now running while the snap is downloading
3. the code path in handlers.go:doPreDownloadSnap() or handlers.go:doUnlinkCurrentSnap() are hit, here firefox is now busy and asyncRefreshOnSnapClose() is called
4. however if firefox is not closed and asyncRefreshOnSnapClose() / continueRefreshOnSnapClose() is aborted it seems no cleanup of the download is happening
One extra complication of this bug is that we will have to write cleanup code that checks the state and clear any unexpected snaps in /var/lib/snapd/snaps that are not either part of a pre-download or in the system. |
|