Skip to content

worker: keep in-flight overlay dirs during orphan sweep - #9695

Merged
taylorsilva merged 3 commits into
concourse:masterfrom
ShravanthReddy:9685-overlay-orphan-in-flight
Sep 8, 2026
Merged

taylorsilva merged 3 commits into
concourse:masterfrom
ShravanthReddy:9685-overlay-orphan-in-flight

Conversation

@ShravanthReddy

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

closes #9685

The overlay sweeper deleted layer/work dirs of volumes that were being created or promoted during the sweep. The volume stayed mounted, then runc hit ENOENT creating /tmp/gdn-init and the container create failed.

  • Drop the live/+init/ snapshot. RemoveOrphanedResources now takes a live isKnown(handle) callback.
  • CleanupOrphanedEntries stats init/ first, then live/ at delete time, so an init→live rename cannot miss both, and a volume created after sweep start is still known.
  • Fail closed: a Stat error other than ErrNotExist (permission, IO) is treated as known, so a transient stat failure cannot mass-delete overlays.
  • Overlay test covers the real race: handle absent from a stale snapshot, present in init/ via live isKnown. Work-only orphans are still deleted. btrfs/naive implement the new signature.

Notes to reviewer

The in-flight overlay test used to pass the handle as known (knownHandles(inFlight)), which is the snapshot case, not the race. It now uses a live Stat of init/ while the snapshot is empty.

To confirm:

go test ./worker/baggageclaim/volume/driver -ginkgo.focus "RemoveOrphanedResources" -count=1 -timeout 60s
go test ./worker/baggageclaim/volume -ginkgo.focus "CleanupOrphanedEntries" -count=1 -timeout 60s

Release Note

  • Fix worker overlay sweeper deleting overlay dirs of volumes being created, which caused runc to fail with ENOENT on /tmp/gdn-init.

RemoveOrphanedResources used a snapshot of live/ and init/ taken at
sweep start. A volume created after that snapshot, or renamed from
init/ to live/ between the two reads, was treated as an orphan and
had its overlay layer or work dir deleted while still mounted. runc
then hit ENOENT creating /tmp/gdn-init.

Pass a live isKnown callback that stats init/ then live/ at delete
time so the handle is always found across the rename. Stat errors
other than ErrNotExist fail closed (treat as known) so a permission
or IO error cannot mass-delete overlays.

concourse#9685

Signed-off-by: Shravanth Reddy <[email protected]>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: ShravanthReddy / name: Shravanth Reddy (8bbaa33)

@taylorsilva

Copy link
Copy Markdown
Member

ShravanthReddy and others added 2 commits August 31, 2026 20:36
chmod 0 on init/ and live/ is not a Stat error for uid 0, so CI
unit-baggageclaim failed with isKnown("any-handle") false. Replace
the dirs with files so Stat returns ENOTDIR, which is not ErrNotExist
even as root.

Signed-off-by: Shravanth Reddy <[email protected]>
Had to implement the Options pattern for Filesystem so we could assert
on the inner funcs. Now the tests really guard against the desired
behaviour.

Rest of the changes are mostly nit-pick stuff, like removing LLM
comments.

Signed-off-by: Taylor Silva <[email protected]>

@taylorsilva taylorsilva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks again for the PR! Overall I think this is the right direction to take this. Most of my feedback is regarding the tests.

I'm going to push a commit in a bit addressing my comments, assuming github doesn't block me, which it sometimes does. If it does block me I'll post my diff here for you to apply.

Comment on lines +183 to +214
It("does not remove an in-flight work dir missing from a stale snapshot", func() {
inFlight := "in-flight-vol"
workPath := filepath.Join(overlaysDir, "work", inFlight)
Expect(os.Mkdir(workPath, 0755)).To(Succeed())

orphanPath := filepath.Join(overlaysDir, "work", "work-only-orphan")
Expect(os.Mkdir(orphanPath, 0755)).To(Succeed())

initDir := filepath.Join(filepath.Dir(overlaysDir), "init")
Expect(os.MkdirAll(initDir, 0755)).To(Succeed())
// Handle is absent from the (empty) snapshot but present in init/
// by the time the sweeper considers this work dir — or it appears
// during the sweep via this live check.
Expect(os.Mkdir(filepath.Join(initDir, inFlight), 0755)).To(Succeed())

isKnown := func(handle string) bool {
_, err := os.Stat(filepath.Join(initDir, handle))
if err == nil {
return true
}
if errors.Is(err, os.ErrNotExist) {
return false
}
return true
}

err := overlayDrv.RemoveOrphanedResources(isKnown)
Expect(err).ToNot(HaveOccurred())

Expect(workPath).To(BeADirectory())
Expect(orphanPath).ToNot(BeADirectory())
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure this is actually testing anything. We should probably just test that we call the passed in func and the behaviour based on what that func returns.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually there is no behaviour change at the driver-level. There's nothing really to test that isn't already covered by existing tests. I think this test can be deleted.

Comment on lines +259 to +261
if isKnown == nil {
isKnown = func(string) bool { return false }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't this result in every volume being deleted? Should probably just return an error.

Comment on lines +291 to +296
defer func() {
_ = os.Remove(initDir)
_ = os.Remove(liveDir)
_ = os.Mkdir(initDir, 0755)
_ = os.Mkdir(liveDir, 0755)
}()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not needed, the BeforeEach() that these files/dirs are made in will do the cleanup for us.

Comment on lines +284 to +286
// chmod 0 is not a Stat error as root (CI unit-baggageclaim).
// Replace the dirs with files so Stat(init/any-handle) returns
// ENOTDIR, which is not ErrNotExist even as uid 0.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Terribly confusing comment. More plain way of saying this:

removing the init/ and live/ dirs and replacing them with files. This will cause os.Stat to return ENOTDIR

@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Sep 4, 2026
@taylorsilva

Copy link
Copy Markdown
Member

Pushed my commit successfully! I address all my comments in that commit. Biggest changes are with the tests. Original tests were mostly trying to test the right thing, they just had a few gaps and were overly verbose in a few spots.

Assuming the PR checks pass and you also don't see any further issues with this, I'll merge it.

@taylorsilva taylorsilva added this to the 8.3.1 milestone Sep 4, 2026
@taylorsilva taylorsilva mentioned this pull request Sep 4, 2026
15 tasks done
@taylorsilva
taylorsilva merged commit 171af79 into concourse:master Sep 8, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

worker: volume sweeper removes overlay dirs of volumes being created, breaking container create

2 participants