Skip to content

A blob drop that dies after its unlink lets a concurrent fork record an image over the missing file #212

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:179-207: drop_blob/1 removes the file, then the row, inside one transaction. img.ex:259-304: record_derived/3. img.ex:414-420: backed/2, which it runs for the new delta blob only.
  • Chain:
    1. create_derived/4 over parent image P reads P's chain.
    2. delete/1 of P commits forget/1. drop_blob/1 then locks base blob B, finds no layer referencing it, and unlinks its file.
    3. That transaction dies before its commit (connection lost, node killed). Row B stays with no file. The comment at img.ex:183-184 leaves such a row to the GC.
    4. The derive inserts its layer rows. The one referencing B passes its foreign key because the row exists, and nothing checks B's file.
  • Effect: a derived image recorded over a base blob that is gone. The GC keeps and reports it as a dangling reference and cannot repair it.
  • Model: image_store_failed_drop violates layersHaveFiles. image_store_fork_vs_delete, the same race with no failing drop, holds. The trace, from spec/ on that branch after npm ci:
    node_modules/.bin/quint run image_store.qnt --main image_store_failed_drop \
      --invariant layersHaveFiles --max-samples 100000 --max-steps 40
  • Repro: not written. With real connections: start create_derived/4 over a parent, delete the parent image, and kill the connection of the drop_blob/1 transaction after its File.rm (or make the row delete fail). Let the derive finish and check the base file.
  • Fix: run backed/2 over every blob of the chain in record_derived/3, not only the delta.
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