Skip to content
This repository was archived by the owner on Nov 19, 2026. It is now read-only.
This repository was archived by the owner on Nov 19, 2026. It is now read-only.

Panic: attempted to update last-writer in lockfile without the write lock #1324

Closed

Description

@tyler92

For some reason, I had an incomplete layer (according to the log file) and the nearest Podman's PlayKube command led to panic in the storage module. A cropped part of the stack trace (see full in the attach):

Sep 07 06:24:54 host podman[468]: time="2022-09-07T06:24:54Z" level=warning msg="Found incomplete layer "b229cb7be9f40343b5938e9ea4c58cbe9245da1ebbda2bd0e1b4600b56036080", deleting it"
Sep 07 06:24:54 host podman[468]: time="2022-09-07T06:24:54Z" level=warning msg="Recovering from API service endpoint handler panic: attempted to update last-writer in lockfile without the write lock, goroutine 43 [running]:
github.com/containers/podman/v4/pkg/api/server.panicHandler.func1.1.1
	github.com/containers/podman/v4/pkg/api/server/handler_panic.go:22 +0x78
panic
	runtime/panic.go:1038 +0x23c
github.com/containers/storage/pkg/lockfile.(*lockfile).Touch
	github.com/containers/[email protected]/pkg/lockfile/lockfile_unix.go:247 +0x198
github.com/containers/storage.(*layerStore).Touch
	github.com/containers/[email protected]/layers.go:1897 +0x28
github.com/containers/storage.(*layerStore).saveLayers
	github.com/containers/[email protected]/layers.go:498 +0x1d4
github.com/containers/storage.(*layerStore).Load
	github.com/containers/[email protected]/layers.go:422 +0x534
github.com/containers/storage.(*store).newLayerStore
	github.com/containers/[email protected]/layers.go:559 +0x39c
github.com/containers/storage.(*store).LayerStore
	github.com/containers/[email protected]/store.go:913 +0x398
github.com/containers/storage.(*store).layersByMappedDigest
	github.com/containers/[email protected]/store.go:3030 +0x40
github.com/containers/storage.(*store).LayersByUncompressedDigest
	github.com/containers/[email protected]/store.go:3072 +0xf8
github.com/containers/image/v5/storage.(*storageImageSource).getBlobAndLayerID
	github.com/containers/image/[email protected]/storage/storage_image.go:202 +0x70
github.com/containers/image/v5/storage.(*storageImageSource).GetBlob
	github.com/containers/image/[email protected]/storage/storage_image.go:163 +0x98
github.com/containers/image/v5/internal/image.(*manifestOCI1).ConfigBlob
	github.com/containers/image/[email protected]/internal/image/oci.go:66 +0x148
github.com/containers/image/v5/internal/image.(*manifestOCI1).OCIConfig
	github.com/containers/image/[email protected]/internal/image/oci.go:92 +0xa8
github.com/containers/podman/v4/libpod.(*storageService).CreateContainerStorage
	github.com/containers/podman/v4/libpod/storage.go:92 +0x1e4
github.com/containers/podman/v4/libpod.(*Container).setupStorage
	github.com/containers/podman/v4/libpod/container_internal.go:506 +0x6e4
github.com/containers/podman/v4/libpod.(*Runtime).setupContainer
	github.com/containers/podman/v4/libpod/runtime_ctr.go:424 +0x1178
github.com/containers/podman/v4/libpod.(*Runtime).newContainer
	github.com/containers/podman/v4/libpod/runtime_ctr.go:236 +0x184
github.com/containers/podman/v4/libpod.(*Runtime).NewContainer
	github.com/containers/podman/v4/libpod/runtime_ctr.go:52 +0xf8
github.com/containers/podman/v4/pkg/specgen/generate.ExecuteCreate
	github.com/containers/podman/v4/pkg/specgen/generate/container_create.go:239 +0x5c
github.com/containers/podman/v4/pkg/specgen/generate.MakePod
	github.com/containers/podman/v4/pkg/specgen/generate/pod_create.go:66 +0x4c0
github.com/containers/podman/v4/pkg/domain/infra/abi.(*ContainerEngine).playKubePod
	github.com/containers/podman/v4/pkg/domain/infra/abi/play.go:464 +0x1820
github.com/containers/podman/v4/pkg/domain/infra/abi.(*ContainerEngine).PlayKube
	github.com/containers/podman/v4/pkg/domain/infra/abi/play.go:174 +0x12ec
github.com/containers/podman/v4/pkg/api/handlers/libpod.PlayKube

Full log with panic: podman-panic.log

It seems like the wrong condition - layers.go#L397 because Locked function may return true even if the lock is owned by other thread. So the lock may be released at any time after the Locked function returns true. Probably we should acquire reader lock in newLayerStore.

Activity

  1. rhatdan commented on Sep 7, 2022

    @rhatdan
    Member
  2. nalind commented on Sep 7, 2022

    @nalind
    Member

    We need to be taking either a read lock or a write lock before calling the new layer store's Load() method in newLayerStore(). At that point Locked() will return the correct value, as it would if we called LoadLocked() instead.

  3. tyler92 commented on Sep 16, 2022

    @tyler92
    ContributorAuthor

    I created a PR but can't do a good enough check.

  4. mtrmac commented on Oct 14, 2022

    @mtrmac
    Collaborator

    I’m missing something about what has happened here. Looking at the backtrace, there are two goroutines waiting for graphLock:

    github.com/containers/storage.(*store).LayerStore(0x240ae40)
    	github.com/containers/[email protected]/store.go:890 +0x58
    

    and that’s fine.

    But there also two goroutines holding graphLock:

    github.com/containers/storage.(*store).newLayerStore(0x240ae40, {0x25a24b0, 0x26}, {0x25a2510, 0x2e}, {0x13d99bc, 0x2990000})
    	github.com/containers/[email protected]/layers.go:559 +0x39c
    github.com/containers/storage.(*store).LayerStore(0x240ae40)
    	github.com/containers/[email protected]/store.go:913 +0x398
    

    and

    github.com/containers/storage.(*store).getGraphDriver(0x240ae40)
    	github.com/containers/[email protected]/store.go:866 +0xbc
    github.com/containers/storage.(*store).LayerStore(0x240ae40)
    	github.com/containers/[email protected]/store.go:900 +0x178
    

    Does anyone know what is going on here?

    (I don’t fully understand the operation of graphLock, but for now I’m focusing on that one simple mystery.)

  5. mtrmac commented on Oct 14, 2022

    @mtrmac
    Collaborator

    We need to be taking either a read lock or a write lock before calling the new layer store's Load() method in newLayerStore(). At that point Locked() will return the correct value

    But Locked() had to return true even without owning the lock, otherwise we couldn’t get to the saveLayers code path. AFAICS that’s another problem, #1388 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions