Hash sum mismatch fetching apt data

My build failed with the following error for some reason

SystemError: E:Failed to fetch copy:~/.cache/snapcraft/stage-packages/apt/9f556022766dec6938a13bd3c7f93a832c18dc309f860f720b5a14cb050914bad2fa2ce4812618d32fb12bf78b169492/var/lib/apt/lists/partial/tw.archive.ubuntu.com_ubuntu_dists_xenial-security_multiverse_dep11_icons-64x64.tar.gz  Hash Sum mismatch, E:Failed to fetch copy:~/.cache/snapcraft/stage-packages/apt/9f556022766dec6938a13bd3c7f93a832c18dc309f860f720b5a14cb050914bad2fa2ce4812618d32fb12bf78b169492/var/lib/apt/lists/partial/tw.archive.ubuntu.com_ubuntu_dists_xenial-backports_main_dep11_icons-64x64.tar.gz  Hash Sum mismatch, E:Some index files failed to download. They have been ignored, or old ones used instead.

I’ve changed the mirror I used but still encounters it, any ideas? apt update runs perfectly without errors, just snapcraft failing for some reason.

Workaround

Use snapcraft cleanbuild with LXD containers instead

The error message seems to imply that the archive is being copied from a local file, which perhaps means the broken file was cached. Have you tried doing a snapcraft clean first?

Well I tried rm -r ~/.cache/snapcraft once but it didn’t work, snapcraft clean as well.

I change the source archive to archive.ubuntu.com, still reproduced the same issue.

Was the error still referring to tw.archive? If all mirrors have the same broken file with the same checksum, then it must be an actual bad file that was synchronized.

Nope the error referring archive.ubuntu.com instead.

Do you have a proxy setup?

No as well, just a simple NAT to the internet.

Okay, so it must be a broken file that was synchronized indeed. It should sort itself out in the next sync. The cleanbuild is likely working because it has a different configuration for apt. I doubt we have multiverse enabled by default there.

The problem seems to be solved after I remove the shouldn’t-be-available universe and multiverse components from the security.ubuntu.com archive sourceline.

Here is what’s left in the sources.list:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
## Software provided at the release
deb http://tw.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse 
#deb-src http://tw.archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse 

## Regular software fixes after the release
deb http://tw.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse 
#deb-src http://tw.archive.ubuntu.com/ubuntu/ xenial-updates main restricted universe multiverse 

## Security fixes from the SecurityTeam
deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted
#deb-src http://security.ubuntu.com/ubuntu/ xenial-security main restricted 

## Backported Software with less testing
#deb http://tw.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse 
#deb-src http://tw.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse 

## Software provided by Canonical, ltd. and it's partners
deb http://archive.canonical.com/ubuntu xenial partner
#deb-src http://archive.canonical.com/ubuntu xenial partner

I still don’t know why apt update works in the previous configuration though.

FYI, I face the same issue as well and commenting out security.ubuntu.com and bionic-proposed archives lines fixed the issued for me.

Same problem still happens on a fresh 18.04 install immediately after installing snapcraft and running it for the first time.

E:Failed to fetch copy:/home/al/.cache/snapcraft/stage-packages/apt/8258f62dc19fdf293af3016720501f6a4ab85794b08d971374b77ddc6b7fc8d775345d31004954d4d6f0c3ec59120b14/var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_bionic-security_main_dep11_icons-48x48.tar.gz  Hash Sum mismatch