Skip to content

A failed derive removes a delta file another image was already recorded on #211

Backlog

Description

@markovejnovic

Found by model checking (the Quint specs in #206). A counterexample in the model, each step read in the code at e281a48. Not reproduced on a running system.

  • Where: lib/hyper/img.ex:249-257 (record_derived_or_rollback/4). record_or_rollback/5 at img.ex:311-319 has the same shape for base images.
  • Chain:
    1. Fork A publishes delta bytes D over parent P1. publish/2 creates the file, origin :created.
    2. Fork B publishes the same bytes D over parent P2. The file exists, origin :reused, and B's record_derived/3 commits.
    3. A's record_derived/3 fails. In the model P1 is being deleted, so a chain row fails its foreign key.
    4. A's rollback removes the file with File.rm, under no lock and with no reference check.
  • Effect: B's image is recorded over a blob whose file is gone. Leases (No VM takes an image lease, so Img.delete/1 removes an image a VM is running from #207) do not cover this: no delete of B's image is involved.
  • Trigger: narrow. It needs two publishes of byte-identical content, one of which fails to record.
  • Read in the code, not modelled: publish/2 (img.ex:334-348) is exists-then-rename, so two publishers of the same bytes can both get :created. Its cross-device path (img.ex:358-367) copies straight to the final name and removes it when the copy fails, which a reuser may already have seen.
  • Model: image_store_shared_delta violates layersHaveFiles. The trace, from spec/ on that branch after npm ci:
    node_modules/.bin/quint run image_store.qnt --main image_store_shared_delta \
      --invariant layersHaveFiles --max-samples 100000 --max-steps 40
  • Repro: not written. With real connections (the :external image tests commit for real): hold a transaction that deletes one parent's image and blob rows, start create_derived/4 over that parent, run a second create_derived/4 with the same delta bytes over another parent to completion, commit the first transaction, and check the delta file.
  • Fix: do not remove on rollback. Leave the file for a GC of unreferenced files (Storage only grows: layer GC, non-deterministic ext4, fork depth, leaked thin ids #126), or remove it only under the blob row lock drop_blob/1 takes, after checking that no layer references it.
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

    bug

    Fields

    No fields configured for issues without a type.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions