Skip to content

Commit

Permalink
ignore ENOENT errors when parsing registries.d files
Browse files Browse the repository at this point in the history
As always listing files in a dir to then read them is racy as the file
might have been removed in the meantime. Thus we must ignore ENOENT
errors when the file is opened.

This is not just a theoretical problem, the reason I am here is because
it caused a flake in the podman CI[1]:
... open /etc/containers/registries.d/podman-test-only-temporary-addition.yaml: no such file or directory

[1] https://api.cirrus-ci.com/v1/artifact/task/6673405799301120/html/int-podman-fedora-40-root-host-boltdb.log.html#t--Podman-push-podman-push-to-local-registry-with-authorization--1

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jan 27, 2025
1 parent b5c6aff commit 1294122
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docker/registries_d.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"errors"
"fmt"
"io/fs"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -129,6 +130,11 @@ func loadAndMergeConfig(dirPath string) (*registryConfiguration, error) {
configPath := filepath.Join(dirPath, configName)
configBytes, err := os.ReadFile(configPath)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
// file must have been removed between the directory listing
// and the open call, ignore that as it is a expected race
continue
}
return nil, err
}

Expand Down

0 comments on commit 1294122

Please sign in to comment.