Skip to content

Conversation

@vvoland
Copy link
Contributor

@vvoland vvoland commented Dec 12, 2025

- What I did

Start the metadata transaction before creating the overlay2 directory. This ensures that if driver.Create() fails, we can properly cancel the transaction. Previously, if StartTransaction() failed after driver.Create() succeeded, the defer cleanup would not run (not registered yet), leaving an orphaned overlay2 directory.

Related to #45939

- How I did it

The fix reorders operations so that:

  1. Transaction is started first (no filesystem changes yet)
  2. Overlay2 directory is created second (transaction ready for cleanup)
  3. Defer is registered after both succeed (tx is guaranteed non-nil)

If driver.Create() fails, the transaction is explicitly cancelled before returning. The nil check for tx in the defer is no longer needed since tx is guaranteed to exist when the defer runs.

- How to verify it

  • All existing layer tests pass: go test ./daemon/internal/layer/...
  • golangci-lint passes with 0 issues
  • Code review confirms the fix prevents the orphan scenario
Fix potential creation of orphaned overlay2 layers

Start the metadata transaction before creating the overlay2 directory.
This ensures that if driver.Create() fails, we can properly cancel the
transaction. Previously, if StartTransaction() failed after driver.Create()
succeeded, the defer cleanup would not run (not registered yet), leaving
an orphaned overlay2 directory.

The fix reorders operations so that:
1. Transaction is started first (no filesystem changes yet)
2. Overlay2 directory is created second (transaction ready for cleanup)
3. Defer is registered after both succeed (tx is guaranteed non-nil)

If driver.Create() fails, the transaction is explicitly cancelled before
returning. The nil check for tx in the defer is no longer needed since
tx is guaranteed to exist when the defer runs.

Related to moby#45939

Signed-off-by: Jan Scheffler <jan.scheffler@qodev.ai>
(cherry picked from commit 7000454)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
@vvoland
Copy link
Contributor Author

vvoland commented Dec 12, 2025

@thaJeztah You good with backporting this to 29.1.3?

@thaJeztah
Copy link
Member

Yup, seems sane to me; it's effectively just swapping the order to allow an early return.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vvoland vvoland merged commit fbf3ed2 into moby:docker-29.x Dec 12, 2025
193 of 195 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants