Skip to content

fix: baggageclaim: fix overlay driver stacking mounts on worker restart - #9723

Merged
taylorsilva merged 4 commits into
concourse:masterfrom
Kump3r:fix_bind_mount
Sep 18, 2026
Merged

taylorsilva merged 4 commits into
concourse:masterfrom
Kump3r:fix_bind_mount

Conversation

@Kump3r

@Kump3r Kump3r commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Changes proposed by this PR

closes #9722

What

OverlayDriver.Recover() called bindMount/overlayMount for every
on-disk volume on startup without checking whether those paths were
already mounted. Linux allows stacking bind mounts silently, so each
in-place process restart (BOSH update, monit, etc.) added a full extra
copy of all volume mounts. After enough restarts the mount table hit
its kernel limit, mount(2) returned ENOSPC, and the worker entered a
crash loop that made things worse on every iteration.

How

  • bindMount and overlayMount now check mountinfo.Mounted() before
    calling syscall.Mount and skip silently if already present.
  • Recover() tracks which paths it mounts in the current pass and
    unmounts them if any later step fails, preventing partial mount state
    from compounding on the next restart.
  • moby/sys/mountinfo was already an indirect dependency; promoted to
    direct.

Tests

  • Unit: Recover() called N times on already-mounted volumes — mount
    count stays flat.
  • Unit: Recover() with a bad volume mid-loop — previously mounted
    volumes are rolled back.
  • Integration: worker bounced without prior unmount (dirty restart) —
    volumes recover correctly and mount count does not grow across
    repeated bounces.

@kristianstanchev

Copy link
Copy Markdown
Contributor

Example error message in production:

{"timestamp":"2026-09-17T11:27:05.773012935Z","level":"error","source":"worker","message":"worker.baggageclaim.failed-to-recover-volume-driver","data":{"error":"recover bind mount: no space left on device","session":"2"}}
{"timestamp":"2026-09-17T11:27:26.028301997Z","level":"error","source":"worker","message":"worker.baggageclaim.failed-to-recover-volume-driver","data":{"error":"recover bind mount: no space left on device","session":"2"}}
{"timestamp":"2026-09-17T11:27:46.180025145Z","level":"error","source":"worker","message":"worker.baggageclaim.failed-to-recover-volume-driver","data":{"error":"recover bind mount: no space left on device","session":"2"}}
{"timestamp":"2026-09-17T11:28:06.427830771Z","level":"error","source":"worker","message":"worker.baggageclaim.failed-to-recover-volume-driver","data":{"error":"recover bind mount: no space left on device","session":"2"}}

@taylorsilva taylorsilva added this to the 8.3.1 milestone Sep 17, 2026
@taylorsilva taylorsilva mentioned this pull request Sep 17, 2026
15 tasks done
@taylorsilva taylorsilva moved this from Todo to In Progress in Pull Requests Sep 17, 2026
Comment on lines +129 to +139
// tracks paths mounted during this Recover call so they
// can be rolled back if a later step fails.
var mountedThisPass []string
rollback := func() {
for _, path := range mountedThisPass {
if err := syscall.Unmount(path, 0); err != nil && !errors.Is(err, syscall.EINVAL) {
driver.logger.Error("rollback-unmount", err, lager.Data{"path": path})
}
}
}

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.

I'm not sure about the utility of doing this rollback. It assumes the state prior to Recover() being called is a better place to leave things in if there's a failure of any kind. Without knowing what error we're dealing with this may or may not be useful. Why is unmounting what we've successfully mounted so far a good thing to do?

Another question: why do we ignore EINVAL errors ("invalid argument") during rollback?


I think it would make sense to do this if we know why. I see in the issue you wrote:

Defect 2 - Recover() does not roll back mounts on error (line 115–162)

Why is this a defect?

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.

This rollback function also seems to be the entire reason for adding the boolean return value to bindMount() and overlayMount().

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.

If we end up keeping this, we should also rollback in the reverse order of the list to correctly rollback any parent->child relationships. Current setup would rollback a parent before a child.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me provide some clarity although I do agree with the challenge and you are right to question, also the reversed order is an actual bug.

To the point why do it in the first place - The rollback was added as defense-in-depth for the case where Recover() mounts volumes 1..K successfully and then fails on K+1, leaving a partial state. The theory was: better to clean up what we added than leave half-mounted volumes.vBut given that the primary fix is the idempotency check (mountinfo.Mounted() before every syscall.Mount), partial mounts from a failed pass are already harmless on the next restart — the idempotency check will skip them. So rollback doesn't actually add safety, just complexity. Removing it now.

The bool return only exists for rollback - Yup, without rollback there's no reason to distinguish "we mounted it this pass" from "it was already mounted". Both bindMount and overlayMount go back to returning plain error.

Rollback order is wrong (parent before child) - Yes, I missed this and its a real bug: the list was ordered roots first then CoWs, so rollback would try to unmount a root bind-mount while its CoW overlay was still live - that would fail with EBUSY. The fix would be to reverse the list before iterating. But since we're dropping rollback entirely, this doesn't need to be fixed - it goes away.

Comment on lines +150 to +151

runner.Bounce()

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.

Why do we bounce the runner in the BeforeEach()? If we want to test multiple restarts we could do a for loop in the It() instead where we restart the runner multiple times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid point - the test is clearer if the full scenario (create → bounce → assert → bounce again → assert) lives inside the It block rather than split across BeforeEach and It. Both bounces are now inside the It, so the reader can follow the whole story without jumping between blocks.


AfterEach(func() {
_ = syscall.Unmount(rootVolume.Path(), 0)
_ = syscall.Unmount(cowVolume.Path(), 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.

nit: why ignore errors? We check for errors in the other tests in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used _ = here because AfterEach runs even when the test body fails, and
at that point I wasn't certain whether the mounts would still be present -
if the test failed mid-bounce, cleanup might be in an unknown state and a
hard Expect would produce a noisy secondary failure that masks the real one.
That said, the test is structured so both volumes are always mounted by the
time AfterEach runs, so the uncertainty doesn't actually exist. Fixed to use
Expect(err).NotTo(HaveOccurred())

@Kump3r

Kump3r commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Validated the fix by compiling the binary and switching to the bosh VM, with the same steps described in the issue:

worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# mount | grep "$CONCOURSE_WORK_DIR" | wc -l
225
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# monit restart worker
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# mount | grep "$CONCOURSE_WORK_DIR" | wc -l
229
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# mount | grep "$CONCOURSE_WORK_DIR" | wc -l
232
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# monit restart worker
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# mount | grep "$CONCOURSE_WORK_DIR" | wc -l
238
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# monit restart worker
worker/fa3d0fb7-3650-4e4c-a375-830664466ce8:/var/vcap/packages/concourse/bin# mount | grep "$CONCOURSE_WORK_DIR" | wc -l
238

As you can see with the new binary the cound is not multiplied on each restart

@Kump3r
Kump3r requested a review from taylorsilva September 18, 2026 10:23

@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 for making the changes Kalin! LGTM now. I'll make sure this makes it over to 8.3.1

@taylorsilva
taylorsilva merged commit 6b0f499 into concourse:master Sep 18, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Pull Requests Sep 18, 2026
@Kump3r

Kump3r commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick response as always and for taking a look

suhlig added a commit to uhlig-it/infrastructure that referenced this pull request Oct 3, 2026
soda entered an OOM loop on 2026-10-03: VictoriaMetrics grew its caches to ~4.5 GiB under the default -memory.allowedPercent=60, filled the 4 GiB swap file, and the kernel killed it six times, taking the Concourse and metrics tailnet services down with it.

- VictoriaMetrics: cap caches with -memory.allowedBytes=1500MB and add MemoryHigh=1400M/MemoryMax=1800M so a spike is reclaimed inside the unit instead of triggering a global OOM. Slow restarts to RestartSec=10 (the 100ms default re-warmed the caches and fed the loop). Keep the basic-auth password out of the Ansible log with no_log.

- swap: add a second 4 GiB swap file (8 GiB total) and raise vm.swappiness to 30.

- Concourse web/worker: shield with OOMScoreAdjust=-500 via systemd drop-ins. Pin 8.3.1, which fixes the worker mount-table leak (concourse/concourse#9723), and add the mountinfo_metric exporter that made the leak visible.

- Add machines/soda.yml and wire it into site.yml.
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.

baggageclaim: overlay driver Recover() stacks bind-mounts on each in-place restart → ENOSPC crash loop

3 participants