/var/lib/snapd/snaps/ is not cleaned up

Bug #2052666 reported by Ivan Kurnosov
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
snapd
Fix Committed
Undecided
Unassigned

Bug Description

I'm running ubuntu 20.04 and recently discovered that `/var/lib/snapd/snaps/` contains a lot of quite old snaps that I expect to be cleaned up.

For instance skype:

```
# ls -la /var/lib/snapd/snaps/skype_*
-rw------- 1 root root 146771968 Apr 19 2023 /var/lib/snapd/snaps/skype_266.snap
-rw------- 1 root root 146771968 Apr 24 2023 /var/lib/snapd/snaps/skype_267.snap
-rw------- 1 root root 147140608 Apr 25 2023 /var/lib/snapd/snaps/skype_269.snap
-rw------- 1 root root 147746816 May 24 2023 /var/lib/snapd/snaps/skype_274.snap
-rw------- 1 root root 148983808 Jun 16 2023 /var/lib/snapd/snaps/skype_280.snap
-rw------- 1 root root 189390848 Aug 17 12:56 /var/lib/snapd/snaps/skype_291.snap
-rw------- 1 root root 183963648 Oct 2 20:54 /var/lib/snapd/snaps/skype_301.snap
-rw------- 1 root root 183963648 Oct 6 22:56 /var/lib/snapd/snaps/skype_302.snap
-rw------- 1 root root 184414208 Nov 1 20:45 /var/lib/snapd/snaps/skype_306.snap
-rw------- 1 root root 184659968 Dec 5 23:00 /var/lib/snapd/snaps/skype_314.snap
-rw------- 1 root root 185167872 Dec 8 18:47 /var/lib/snapd/snaps/skype_317.snap
-rw------- 1 root root 185163776 Dec 11 22:19 /var/lib/snapd/snaps/skype_318.snap
-rw------- 1 root root 185167872 Dec 14 11:36 /var/lib/snapd/snaps/skype_320.snap
-rw------- 1 root root 185294848 Jan 23 22:58 /var/lib/snapd/snaps/skype_323.snap
-rw------- 1 root root 187752448 Jan 31 19:28 /var/lib/snapd/snaps/skype_325.snap
-rw------- 1 root root 187752448 Feb 5 16:23 /var/lib/snapd/snaps/skype_326.snap
```

yet only 2 versions are actually installed:

```
# snap list --all|grep -i skype
skype 8.111.0.607 323 latest/stable skype** -
skype 8.110.0.218 320 latest/stable skype** disabled
```

But even here there is some oddity - see that the installed are 320 and 323, but also 325 and 326 are in the snaps :shrug:

I wouldn't bother otherwise, but currently `/var/lib/snapd/snaps/` already takes 15Gb and over the time it will only grow more.

This machine is rebooted regularly (usually every kernel release, so at least once or twice a month), so it definitely is not that some cleanup routine that didn't have chance to trigger the actual cleanup.

Am I doing something wrong and should I somehow clean it up manually? Or is it some well known bug, which I honestly couldn't find.

PS: this question is the exact copy from my original post at [askubuntu.com](https://askubuntu.com/q/1502686/17485) and [forum.snapcraft](https://forum.snapcraft.io/t/var-lib-snapd-snaps-is-not-cleaned-up/38874)

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

This affects me too. Mostly with one snap:

```
$ snap list --all miriway
Name Version Rev Tracking Publisher Notes
miriway 109-mir2.16.2 2794 latest/beta alangriffiths✪ disabled,classic
miriway 113-mir2.16.3 2981 latest/beta alangriffiths✪ classic
$ ls -1 /var/lib/snapd/snaps/miriway*
/var/lib/snapd/snaps/miriway_2444.snap
/var/lib/snapd/snaps/miriway_2627.snap
/var/lib/snapd/snaps/miriway_2638.snap
/var/lib/snapd/snaps/miriway_2699.snap
/var/lib/snapd/snaps/miriway_2759.snap
/var/lib/snapd/snaps/miriway_2770.snap
/var/lib/snapd/snaps/miriway_2794.snap
/var/lib/snapd/snaps/miriway_2824.snap
/var/lib/snapd/snaps/miriway_2839.snap
/var/lib/snapd/snaps/miriway_2859.snap
/var/lib/snapd/snaps/miriway_2868.snap
/var/lib/snapd/snaps/miriway_2895.snap
/var/lib/snapd/snaps/miriway_2910.snap
/var/lib/snapd/snaps/miriway_2922.snap
/var/lib/snapd/snaps/miriway_2955.snap
/var/lib/snapd/snaps/miriway_2981.snap
```

This snap is unusual as I run for long periods (usually between reboots - days to weeks), but has updates frequently (I often have it tracking the `main` branch of the Mir, which updates several times a day).

Hence, I suspect that versions are downloaded pending the snap closing that are unused but not deleted. Either because another version comes along in the meantime, or because I refresh to another channel, or I install a local build.

Empirically, cleaning up manually doesn't seem to cause problems:

```
$ ls -1 /var/lib/snapd/snaps/miriway* | grep -v -e 2794 -e 2981 | xargs sudo rm
```

Revision history for this message
myrtille (akm1984) wrote :

I'm also affected, the most common one is firefox (but also chromium or vscode).

ls -la /var/lib/snapd/snaps/firefox_*
-rw------- 1 root root 256360448 Jul 3 2023 /var/lib/snapd/snaps/firefox_2800.snap
-rw------- 1 root root 256897024 Jul 9 2023 /var/lib/snapd/snaps/firefox_2880.snap
-rw------- 1 root root 248733696 Aug 2 2023 /var/lib/snapd/snaps/firefox_2952.snap
-rw------- 1 root root 248733696 Aug 25 13:25 /var/lib/snapd/snaps/firefox_3026.snap
-rw------- 1 root root 248418304 Sep 24 11:36 /var/lib/snapd/snaps/firefox_3131.snap
-rw------- 1 root root 252153856 Oct 9 00:42 /var/lib/snapd/snaps/firefox_3206.snap
-rw------- 1 root root 251990016 Nov 20 18:22 /var/lib/snapd/snaps/firefox_3358.snap
-rw------- 1 root root 257859584 Jan 8 23:50 /var/lib/snapd/snaps/firefox_3600.snap
-rw------- 1 root root 257945600 Jan 17 11:35 /var/lib/snapd/snaps/firefox_3626.snap
-rw------- 1 root root 275263488 Jan 25 06:33 /var/lib/snapd/snaps/firefox_3687.snap
-rw------- 1 root root 274821120 Feb 4 07:53 /var/lib/snapd/snaps/firefox_3728.snap
-rw------- 1 root root 275251200 Feb 8 10:43 /var/lib/snapd/snaps/firefox_3779.snap
-rw------- 1 root root 279584768 Feb 21 09:03 /var/lib/snapd/snaps/firefox_3836.snap
snap list --all|grep -i firefox
firefox 121.0.1-1 3626 latest/stable mozilla** disabled
firefox 122.0.1-1 3779 latest/stable mozilla** -

That being said, I suspect this happens when the snap forces an update (as the apps that multiply are the ones that I commonly have 'always open').

Revision history for this message
myrtille (akm1984) wrote :

I'm wondering if this is not maybe packages that were downloaded (as an upcoming upgrade) but never installed because a newer version was downloaded before it could be installed.

Today I did a snap refresh and it shows:

:~$ snap refresh --list
Name Version Rev Size Publisher Notes
firefox 123.0.1-1 3941 280MB mozilla✓ -

The current 'new' additions for firefox in /var/lib/snapd/snaps/firefox* are:
-rw------- 1 root root 263M Feb 8 10:43 firefox_3779.snap
-rw------- 1 root root 267M Mar 5 00:49 firefox_3836.snap
-rw------- 1 root root 268M Mar 6 14:37 firefox_3941.snap

After updating firefox, the current version of firefox 'installed' now are:
firefox 122.0.1-1 3779 latest/stable mozilla✓ disabled
firefox 123.0.1-1 3941 latest/stable mozilla✓ -

Changed in snapd:
status: New → Fix Committed
milestone: none → 2.62
Revision history for this message
Mateusz Stachowski (stachowski-mateusz) wrote :

The situation described by myrtille (akm1984) in comment #3 happend on my install atleast once.

And it also was Firefox. The snap didn't update to newer version, because Firefox was running, but it did download that new version of snap package. Then in next refresh there was even newer snap package, so it updated to that version. The previously downloaded snap package remained in /var/lib/snapd/snaps, so I ended up with three packages for Firefox.

Firefox isn't my main browser so it mostly isn't running and I don't know if that is still happening.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.