Can't run any podman command anymore - panic: runtime error: invalid memory address or nil pointer dereference
Discussed in https://github.com/containers/podman/discussions/24736
Originally posted by dozenposture December 2, 2024 I've used to have about 20 containers running without issues. While trying to update an image, I've found podman can't execute any command anymore.
It really doesn't matter which command I try to run, I always get the following error message:
podman@host:~> podman info
ERRO[0000] Refreshing container a2dea400161ecc6b8440e937e4fb745a6bda8fc87056ddc14c4289dfc560c6da: acquiring lock 2 for container a2dea400161ecc6b8440e937e4fb745a6bda8fc87056ddc14c4289dfc560c6da: file exists
WARN[0000] Found incomplete layer "6d1aab23cceb2aa47ce43e610416609023b6a0dc576c7b383b3eccf30ab6efd6", deleting it
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x100 pc=0x5633e1fec837]
goroutine 1 [running]:
github.com/containers/storage.(*layerStore).load(0xc000460280, 0x1)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/layers.go:917 +0xff7
github.com/containers/storage.(*store).newLayerStore(0x3b?, {0xc000049ef0, 0x28}, {0xc00060f8c0, 0x3b}, {0x0, 0x0}, {0x5633e327af18, 0xc000146d80}, 0x0)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/layers.go:1156 +0x6e5
github.com/containers/storage.(*store).getLayerStoreLocked(0xc0005ac000)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:1125 +0x25d
github.com/containers/storage.(*store).getLayerStore(0xc0005ac000)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:1141 +0x8f
github.com/containers/storage.(*store).writeToAllStores(0xc0005ac000, 0xc0005244c0)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:1401 +0x4c
github.com/containers/storage.(*store).DeleteContainer(0x93?, {0xc0005dcb00?, 0x0?})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:2703 +0x38
github.com/containers/podman/v5/libpod.(*storageService).DeleteContainer(0xc000116600, {0xc00060f500?, 0xc000260fc0?})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/storage.go:177 +0x72
github.com/containers/podman/v5/libpod.(*Container).teardownStorage(0xc0004b8780)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/container_internal.go:603 +0x314
github.com/containers/podman/v5/libpod.(*Runtime).removeContainer(0xc000505180, {0x5633e3267d90, 0x5633e4032600}, 0xc0004b8780, {0x0, 0x1, 0x0, 0x0, 0x0, 0x0, ...})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime_ctr.go:981 +0x1888
github.com/containers/podman/v5/libpod.(*Runtime).refresh(0xc000505180, {0x5633e3267d90, 0x5633e4032600}, {0xc0005130c0, 0x1f})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime.go:871 +0x52d
github.com/containers/podman/v5/libpod.makeRuntime({0x5633e3267d90, 0x5633e4032600}, 0xc000505180)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime.go:637 +0x1bce
github.com/containers/podman/v5/libpod.newRuntimeFromConfig({0x5633e3267d90, 0x5633e4032600}, 0xc0000c4008, {0xc000525660, 0x0, 0xa?})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime.go:213 +0x30e
github.com/containers/podman/v5/libpod.NewRuntime({0x5633e3267d90, 0x5633e4032600}, {0xc000525660, 0x0, 0x0})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime.go:171 +0x5a
github.com/containers/podman/v5/pkg/domain/infra.getRuntime({0x5633e3267d90, 0x5633e4032600}, 0xc0004a4100, 0xc000525898)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/runtime_libpod.go:228 +0x1edc
github.com/containers/podman/v5/pkg/domain/infra.GetRuntime.func1()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/runtime_libpod.go:46 +0x65
sync.(*Once).doSlow(0x1c?, 0xc0004be400?)
/usr/lib64/go/1.23/src/sync/once.go:76 +0xb4
sync.(*Once).Do(...)
/usr/lib64/go/1.23/src/sync/once.go:67
github.com/containers/podman/v5/pkg/domain/infra.GetRuntime({0x5633e3267d90?, 0x5633e4032600?}, 0x5633e2a79cfa?, 0xe?)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/runtime_libpod.go:45 +0x55
github.com/containers/podman/v5/pkg/domain/infra.NewLibpodImageRuntime(0xc0005259b0?, 0xc0004bbab8?)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/runtime_proxy.go:24 +0x27
github.com/containers/podman/v5/pkg/domain/infra.NewImageEngine(0x5633e2a79cfa?)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/runtime_abi.go:31 +0x4b
github.com/containers/podman/v5/cmd/podman/registry.NewImageEngine(0x5633e3f3b3c0?, {0x5633e4009e00?, 0x9?, 0x5633e2da6e58?})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/registry/registry.go:50 +0x54
main.persistentPreRunE(0x5633e3f3b3c0, {0x5633e4032600, 0x0, 0x0})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/root.go:317 +0x6f9
github.com/spf13/cobra.(*Command).execute(0x5633e3f3b3c0, {0xc0000400d0, 0x0, 0x0})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/spf13/cobra/command.go:956 +0x931
github.com/spf13/cobra.(*Command).ExecuteC(0x5633e3f23e00)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/spf13/cobra/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/spf13/cobra/command.go:1041
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/spf13/cobra/command.go:1034
main.Execute()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/root.go:116 +0xb4
main.main()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/main.go:61 +0x4b2
I've browsed for similar issues and I've found something about lingering. The podman user has lingering enabled (since the beginning)
Can someone please help me out understanding what went wrong and how to fix this? Thanks!
WARN[0000] Found incomplete layer "6d1aab23cceb2aa47ce43e610416609023b6a0dc576c7b383b3eccf30ab6efd6", deleting it
Sounds like your storage is corrupted, so the easiest thing would be to remove the container storage and start from an empty storage again and recreate your containers.
Of course it would be good to understand what happend there and certainly it should never panic. AFAICT https://github.com/containers/storage/blob/main/layers.go#L917 failed from the stack trace and that can only happen if the layer would be nil which means r.layers contains a nil layer somehow. Just reading the function there I do not see how this could happen though, we seem to access the layer in several places before so if it would be nil it should have failed much earlier.
Are you running rootless? If so what is the output of cat ~/.local/share/containers/storage/overlay-layers/layers.json?
@mtrmac @giuseppe Ideas?
Oh I see the issue in the c/storage code. While iterating r.layers r.deleteInternal() while remove the element from r.layers as such the slice is modified while we iterate over it which is not safe as we access the last element which no longer exists and we skip one layer.
https://github.com/containers/storage/blob/3021f6ab705ec353ac8d6d644ed3b2dd16f4a9cc/layers.go#L1928-L1930
Thank you very much for your time looking into this issue, I really appreciated it.
This is the requested output (rather long, so I posted there not pollute this thread too much)
What I'm supposed to do exactly to get podman working again? Asking specifically for a command. Please notice that I can't run any podman command without having that error message so I think I'll have to do something manual (just an assumption).
If you don't need need the data delete ~/.local/share/containers/storage. Then just repull the images and recreate your containers.
Note that this dir also contains the data of names volumes in~/.local/share/containers/storage/volumes so if you have anything important backup this directory first before deleting anything.
Otherwise you need to wait for a patch from us to make it work again I think, or try to manually delete the incomplete layer ID from the json file but I don't know if this causes other bad things so just deleting all data seems safest to avoid any storage corruption.
good analysis! load() can't iterate r.layers and delete a layer from there.
If you've a patch, please tag me and I'll review it
Thanks everyone involved in this. I don't think I use named volumes as I explicitly mount directories inside containers but ofc now I'm doubting ;)
I tried inspecting the ~/.local/share/containers/storage/volumes directory and it seems nothing important is there:
homeserver-prd:/home/podman/.local/share/containers/storage/volumes # ls -l ./*/*
./214cf4bfbb7df0d7ac2d80a34c7c35c3150dfe2f083d92d23a114ba42b679a8a/_data:
total 0
./a5f5e19fe028020baa1797607d39f52a903cf887c2b550b8734905a1aaa0b178/_data:
total 0
./e9411f2da8e781e5af85473de9301ede991cec983aef223804379d2a9d84abad/_data:
total 0
-rw-r--r--. 1 231072 231072 0 Sep 14 17:53 .not_mapped
just a .not_mapped file which is empty
I'm unsure now if I want to wait for the patch or delete what needs to be deleted :)
@Luap99 I see that the proposed MR is already merged which is great and it was super fast! When this change will reflect on podman though? Do I have to wait for the next version to be released? (sorry for the potential stupid question but I've limited experience in software lifecycle).
Yes you need to wait for the next version. Generally we make new c/storage release for each podman minor release and the next podman minor release is planned for February so it will take a while most likely. Maybe we can/should backport this fix to a patch release to get it out sooner but even there is no specific timeline so far.
@Luap99: I've just been bitten by this on Fedora Server so I am rebuilding the RPMs locally with the patch. Please consider backporting this fix.
It is already backported in c/storage https://github.com/containers/storage/pull/2193
But podman releases are complicated and take time and there where some other releaser blocker before the holidays so we couldn't get a release out. Now that we are back from holidays we plan for a new 5.3.2 podman release next week which should include this fix.
@Luap99 as suggested above, as a temporary workaround, I deleted all content of ~/.local/share/containers/storage (no named volumes so I deleted everything as I have separate directories that I mount inside containers).
I pulled again all the images (I'm using quadlet files so a simple reboot did the trick) and all of the containers worked expect for one that still give me the same error:
WARN[0000] Found incomplete layer "66495ed88a239f0698c32616e4dc2ad0edf67e6805bdcd638ce04c472ba20e6e", deleting it
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x100 pc=0x55c0804138d7]
goroutine 1 [running]:
github.com/containers/storage.(*layerStore).load(0xc0002daa00, 0x1)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/layers.go:917 +0xff7
github.com/containers/storage.(*store).newLayerStore(0x3b?, {0xc0002422d0, 0x28}, {0xc000045f40, 0x3b}, {0x0, 0x0}, {0x55c0816a3cf8, 0xc0000ccea0}, 0x0)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/layers.go:1156 +0x6e5
github.com/containers/storage.(*store).getLayerStoreLocked(0xc00052a340)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:1125 +0x25d
github.com/containers/storage.(*store).Shutdown(0xc00052a340, 0x0)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/storage/store.go:3582 +0xa5
github.com/containers/common/libimage.(*Runtime).Shutdown(...)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/vendor/github.com/containers/common/libimage/runtime.go:148
github.com/containers/podman/v5/libpod.(*Runtime).Shutdown(0xc0001fd6c0, 0x0)
/home/abuild/rpmbuild/BUILD/podman-5.3.1/libpod/runtime.go:805 +0x19a
github.com/containers/podman/v5/pkg/domain/infra/abi.(*ImageEngine).Shutdown.func1()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/abi/images.go:680 +0x1c
sync.(*Once).doSlow(0x0?, 0x55c0808ee820?)
/usr/lib64/go/1.23/src/sync/once.go:76 +0xb4
sync.(*Once).Do(...)
/usr/lib64/go/1.23/src/sync/once.go:67
github.com/containers/podman/v5/pkg/domain/infra/abi.(*ImageEngine).Shutdown(0x55c08234ce00?, {0x55c08245b620?, 0x55c080eaf83d?})
/home/abuild/rpmbuild/BUILD/podman-5.3.1/pkg/domain/infra/abi/images.go:679 +0x3a
main.Execute()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/root.go:138 +0x215
main.main()
/home/abuild/rpmbuild/BUILD/podman-5.3.1/cmd/podman/main.go:61 +0x4b2
I tried to move the quadlet file of that container under another user on the same system and the container started immediately without any issue. This suggests that the image does not have any problem, AFAIK.
I tried looking for something (file/directory) that contains that string, nothing:
host:/home/podman # find . -name '*66495ed*'
host:/home/podman #
What could be causing that problem? Is there something else that should be deleted to completely get rid of that issue until the new podman version is released?
For those that cannot wait for the next release and totally removing ~/.local/share/containers/storage for rootless or /var/lib/containers/storage due to having volumes with data that you want to save you can edit the layers.json file and remove the entry.
You can find the layers.json file using this:
# Rootful
# find /var/lib/containers/storage -name layers.json
/var/lib/containers/storage/overlay-layers/volatile-layers.json
/var/lib/containers/storage/overlay-layers/layers.json
# Rootless
$ sudo find ~/.local/share/containers/storage -name layers.json
/home/jdoss/.local/share/containers/storage/btrfs-layers/volatile-layers.json
/home/jdoss/.local/share/containers/storage/btrfs-layers/layers.json
Look for this message like this before podman crashes:
WARN[0000] Found incomplete layer "0c85387b0aad34e0e1e9e2eac44a9f39dae2b06131767f0044c8ca0fb08fa14f", deleting it
and then find the entry
{"id":"0c85387b0aad34e0e1e9e2eac44a9f39dae2b06131767f0044c8ca0fb08fa14f","parent":"99db231dad4123c8618bbf52cd6af9839f2bf39f097e86ab592b495a15f41086","created":"2025-01-09T20:07:50.259260078Z","flags":{"incomplete":true}
and remove it. I had two servers that encountered this bug and the entry for both was at the bottom of the layers.json and that was all I needed to do to get back up and running.
thanks!, editing .local/share/containers/storage/overlay-layers/layers.json fixed it for me.
Thanks, got 5.3.2 with dnf-automatic today podman-5.3.2-1.fc41 | Build Info | koji, no more stuck GitHub Actions runners hopefully :).