Skip to content

fix: close boltdb on metadata and mount plugin close#13348

Merged
mxpv merged 1 commit into
containerd:mainfrom
austinvazquez:add-close-db-to-metadata-and-mount-plugins
May 11, 2026
Merged

fix: close boltdb on metadata and mount plugin close#13348
mxpv merged 1 commit into
containerd:mainfrom
austinvazquez:add-close-db-to-metadata-and-mount-plugins

Conversation

@austinvazquez

Copy link
Copy Markdown
Member

Issue

When containerd shuts down its metadata or mount plugin never explicitly close the underlying bboltdb file deferring cleanup of the lock file to the underlying OS. The issue encountered is this causes variable delay for use cases where graceful teardown is desirable to reliably reset containerd.

Summary

This change adds closing of the metadata and mount boltdb to server shutdown.

Garbage collection consideration

The GC plugin currently does not implement Close, thus is skipped in server stop.

Closure of the metadata database should occur after acquiring the read-write lock to ensure no GC cycle is occurring concurrently. Transactions post-closure will result in ErrDatabaseNotOpen. This should be fine as these resources can be scheduled for collection on the next containerd process invocation.

Testing

Updated existing unit tests to close via plugin/manager rather than directly on the raw bolt handle.
Added new test cases to verify the underlying bolt Db is closed by asserting a new transaction returns ErrDatabaseNotOpen.

Co-authored-by: Rob Murray <rob.murray@docker.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses delayed shutdown/teardown by ensuring BoltDB-backed state in the metadata DB and mount manager is explicitly closed during plugin/server shutdown, rather than relying on OS cleanup of lock files.

Changes:

  • Add (*metadata.DB).Close() to close the underlying BoltDB while coordinating with the metadata GC lock.
  • Update mount manager Close() to also close its underlying BoltDB handle.
  • Update/add unit tests to validate DB closure via the manager/DB wrappers and assert ErrDatabaseNotOpen on subsequent transactions.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
core/mount/manager/manager.go Extend mount manager shutdown to close the underlying BoltDB (needs coordination with GC lock).
core/mount/manager/manager_test.go Refactor tests to avoid DB sharing across subtests; add coverage asserting BoltDB is closed via manager close.
core/metadata/db.go Add DB.Close() that closes the underlying transactor if it is an io.Closer, coordinated via wlock.
core/metadata/db_test.go Update cleanups to call DB.Close() and add a test asserting the underlying BoltDB is closed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/mount/manager/manager.go

@dmcgowan dmcgowan 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.

The GC case can be handled in a follow up as its not directly related. When there is a GC error, it can detect context cancellation and just exit. Its mostly cosmetic to avoid seeing a message about gc failure because database closed, that would likely be a rare race anyway.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review May 7, 2026
@mxpv mxpv added this pull request to the merge queue May 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 7, 2026
@mxpv mxpv added this pull request to the merge queue May 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 7, 2026
@mxpv mxpv added this pull request to the merge queue May 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 7, 2026
@mxpv mxpv added this pull request to the merge queue May 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 8, 2026
@mxpv mxpv added this pull request to the merge queue May 8, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 8, 2026
@mxpv mxpv added this pull request to the merge queue May 11, 2026
Merged via the queue into containerd:main with commit c14318e May 11, 2026
176 of 184 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 11, 2026
@austinvazquez austinvazquez deleted the add-close-db-to-metadata-and-mount-plugins branch May 11, 2026 21:57
@austinvazquez austinvazquez added the cherry-pick/2.3.x Change to be cherry picked to release/2.3 label May 11, 2026
@austinvazquez

Copy link
Copy Markdown
Member Author

/cherry-pick 2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@austinvazquez: cannot checkout 2.3: error checking out "2.3": exit status 1 error: pathspec '2.3' did not match any file(s) known to git

Details

In response to this:

/cherry-pick 2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@austinvazquez

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@austinvazquez: new pull request created: #13379

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@austinvazquez austinvazquez added cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch kind/bug size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants