Skip to content

snapshot/containerd: fix wrong errdefs package import#5194

Merged
crazy-max merged 1 commit into
moby:masterfrom
thaJeztah:fix_wrong_errdefs
Jul 27, 2024
Merged

snapshot/containerd: fix wrong errdefs package import#5194
crazy-max merged 1 commit into
moby:masterfrom
thaJeztah:fix_wrong_errdefs

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

I noticed that we were importing the nydus errdefs package here, and looking at f044e0a9468639559db93fe30ee826ce502ac481 (v0.12.0-rc1), which introduced this import, this very likely was meant to be containerd's errdefs package.

The only function consumed from the package is errdefs.IsNotFound which at the time of the commit was not compatible with containerd's errdefs.IsNotFound as it was checking for the nydus error specifically.

Nydus-snapshotter v0.8.0 fixed this incompatibility by aliasing the error to containerd's ErrNotFound and was updated through 483e87725e7fd99124e3e767143687cfd1d59a8e.

Ironically, the original commit f044e0a9468639559db93fe30ee826ce502ac481 broke vendoring, because the Nydus errdefs was no longer vendored. This was fixed in 75dd88efb808edb8c91755565a4417f37b985143, but failed to notice that the missing vendor was due to an incorrect import.

So it looks like things were broken twice in the chain of events (once because the wrong errdefs package did not match the expected error; once because the errdefs package was missing), but all of them landed in v0.12.0-rc1, so nothing broke in a release ':-)

This PR;

  • fixes the wrong import
  • adds a depguard rule to prevent accidental importing of this package

@github-actions github-actions Bot added area/dependencies Pull requests that update a dependency file area/storage labels Jul 26, 2024
@thaJeztah thaJeztah requested review from jedevc and tonistiigi July 26, 2024 23:17
I noticed that we were importing the nydus errdefs package here, and
looking at [f044e0a][1] (v0.12.0-rc1),
which introduced this import, this very likely was meant to be containerd's
errdefs package.

The only function consumed from the package is `errdefs.IsNotFound` which at
the time of the commit was not compatible with containerd's `errdefs.IsNotFound`
as it was [checking for the nydus error specifically][2].

Nydus-snapshotter v0.8.0 fixed this incompatibility by aliasing the error to
[containerd's `ErrNotFound`][3] and was updated through [483e877][4].

Ironically, the original commit [f044e0a][1]
broke vendoring, because the Nydus errdefs was no longer vendored. This was
fixed in [75dd88e][4], but failed to notice
that the missing vendor was due to an incorrect import.

So it looks like things were broken _twice_ in the chain of events (once
because the wrong errdefs package did not match the expected error; once
because the errdefs package was missing), but all of them landed in v0.12.0-rc1,
so nothing broke in a release ':-)

This PR;

- fixes the wrong import
- adds a depguard rule to prevent accidental importing of this package

[1]: moby@f044e0a
[2]: https://github.com/moby/buildkit/blob/f044e0a9468639559db93fe30ee826ce502ac481/vendor/github.com/containerd/nydus-snapshotter/pkg/errdefs/errors.go#L22-L33
[3]: https://github.com/moby/buildkit/blob/f044e0a9468639559db93fe30ee826ce502ac481/vendor/github.com/containerd/nydus-snapshotter/pkg/errdefs/errors.go#L22-L33
[4]: moby@483e877
[5]: moby@75dd88e

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Comment on lines 104 to +106
info, err := c.main.Info(ctx, dgst)
if err != nil {
if errdefs.IsNotFound(err) {
if cerrdefs.IsNotFound(err) {
Copy link
Copy Markdown
Member Author

@thaJeztah thaJeztah Jul 27, 2024

Choose a reason for hiding this comment

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

I wonder if this alway works; some implementations appear to not be returning a typed error. For example;

func (p DescriptorProviderPair) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
if p.InfoProvider != nil {
return p.InfoProvider.Info(ctx, dgst)
}
if dgst != p.Descriptor.Digest {
return content.Info{}, errors.Errorf("content not found %s", dgst)
}

func (p *ciProvider) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
if dgst != p.desc.Digest {
return content.Info{}, errors.Errorf("content not found %s", dgst)
}

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 don't think these are the implementations for the nsFallbackStore

@crazy-max crazy-max merged commit df350f3 into moby:master Jul 27, 2024
@thaJeztah thaJeztah deleted the fix_wrong_errdefs branch July 27, 2024 12:48
@crazy-max crazy-max added this to the v0.16.0 milestone Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dependencies Pull requests that update a dependency file area/storage kind/bug status/merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants