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:
``` snapd/snaps/ firefox* snapd/snaps/ firefox_ 2387.snap /var/lib/ snapd/snaps/ firefox_ 2531.snap snapd/snaps/ firefox_ 2391.snap /var/lib/ snapd/snaps/ firefox_ 2559.snap snapd/snaps/ firefox_ 2393.snap /var/lib/ snapd/snaps/ firefox_ 2937.snap snapd/snaps/ firefox_ 2417.snap
$ ls /var/lib/
/var/lib/
/var/lib/
/var/lib/
/var/lib/
```
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) go:doPreDownloa dSnap() or handlers. go:doUnlinkCurr entSnap( ) are hit, here firefox is now busy and asyncRefreshOnS napClose( ) is called napClose( ) / continueRefresh OnSnapClose( ) is aborted it seems no cleanup of the download is happening
2. user clicks on firefox, it is now running while the snap is downloading
3. the code path in handlers.
4. however if firefox is not closed and asyncRefreshOnS