Skip to content

fix: suppress spurious hostsstore NotFound warning on container removal - #5098

Open
pujitha24 wants to merge 1 commit into
containerd:mainfrom
pujitha24:auto/issue-4678
Open

fix: suppress spurious hostsstore NotFound warning on container removal#5098
pujitha24 wants to merge 1 commit into
containerd:mainfrom
pujitha24:auto/issue-4678

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation:
On Windows, nerdctl run --rm ... (and nerdctl rm) logs a confusing
warning after every container removal:

level=warning msg="failed to remove hosts file for container """
error="hosts-store error\nnot found\nGetFileAttributesEx
...\etchosts\default\: The system cannot find the file specified."

Fixes #4678

Approach:
pkg/containerutil/container_network_manager_windows.go never calls
hostsstore.Acquire/AllocHostsFile (unlike the Linux and generic network
manager code paths), so no hosts-store directory is ever created for a
Windows container. As a result, hostsstore.Delete(id) in
RemoveContainer (pkg/cmd/container/remove.go) always fails with
store.ErrNotFound on Windows, and that failure was unconditionally
logged as a warning.

This is purely a noisy/confusing log message, not a functional bug:
hostsstore.Delete's error was already only logged (soft failure), so
container removal succeeds identically before and after this change.

The fix mirrors the existing nameStore.Release handling a few lines
above in the same function (which already ignores store.ErrNotFound
to tolerate double-release with --rm): hostsstore.Delete's NotFound
error is now ignored for the same reason - the hosts-store entry may
simply never have been allocated for this container/platform/network
mode.

Validation:

  • go build ./... passes.
  • go test ./pkg/... passes (all packages ok, including
    pkg/dnsutil/hostsstore and pkg/store).
  • gofmt -l pkg/cmd/container/remove.go reports no issues.
  • pkg/cmd/container has no unit tests for RemoveContainer (it requires
    a live containerd.Container); this matches the existing test
    coverage pattern for that function (integration-only, via
    cmd/nerdctl/container/container_remove_test.go).

Signed-off-by: Pujitha Paladugu venkat@dema.shop
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com

Motivation:
On Windows, `nerdctl run --rm ...` (and `nerdctl rm`) logs a confusing
warning after every container removal:

  level=warning msg="failed to remove hosts file for container \"<id>\""
  error="hosts-store error\nnot found\nGetFileAttributesEx
  ...\\etchosts\\default\\<id>: The system cannot find the file specified."

Fixes containerd#4678

Approach:
pkg/containerutil/container_network_manager_windows.go never calls
hostsstore.Acquire/AllocHostsFile (unlike the Linux and generic network
manager code paths), so no hosts-store directory is ever created for a
Windows container. As a result, hostsstore.Delete(id) in
RemoveContainer (pkg/cmd/container/remove.go) always fails with
store.ErrNotFound on Windows, and that failure was unconditionally
logged as a warning.

This is purely a noisy/confusing log message, not a functional bug:
hostsstore.Delete's error was already only logged (soft failure), so
container removal succeeds identically before and after this change.

The fix mirrors the existing nameStore.Release handling a few lines
above in the same function (which already ignores store.ErrNotFound
to tolerate double-release with --rm): hostsstore.Delete's NotFound
error is now ignored for the same reason - the hosts-store entry may
simply never have been allocated for this container/platform/network
mode.

Validation:
- go build ./... passes.
- go test ./pkg/... passes (all packages ok, including
  pkg/dnsutil/hostsstore and pkg/store).
- gofmt -l pkg/cmd/container/remove.go reports no issues.
- pkg/cmd/container has no unit tests for RemoveContainer (it requires
  a live containerd.Container); this matches the existing test
  coverage pattern for that function (integration-only, via
  cmd/nerdctl/container/container_remove_test.go).

Signed-off-by: Pujitha Paladugu <venkat@dema.shop>
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 24, 2026 00:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Suppresses a spurious and confusing warning emitted during container removal when the hosts-store entry was never created (notably on Windows), aligning error handling with existing nameStore.Release behavior and resolving the noise reported in #4678.

Changes:

  • Ignore store.ErrNotFound from hostsstore.Delete(id) during RemoveContainer cleanup.
  • Add explanatory comments documenting why NotFound is expected on some platforms/network modes.

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

@AkihiroSuda AkihiroSuda added the platform/Windows/Non-WSL2 Microsoft Windows (non-WSL2) label Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/Windows/Non-WSL2 Microsoft Windows (non-WSL2)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nerdctl on windows shows strange warning: failed to remove hosts file for container

3 participants