Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NRE and Disallow Missing Registration Page Leaves #5741

Closed
wants to merge 3 commits into from

Conversation

mukunku
Copy link

@mukunku mukunku commented Apr 5, 2024

Bug

Fixes: NuGet/Home#13377

Regression? Last working version: The NRE has been there since the code was written in #3462

Description

The original issue is just the wrong variable being used in the if check. However for some reason when doing dotnet tool restore in the dotnet 6 sdk the issue doesn't happen for us. But once we upgraded our project to use dotnet 8 the NRE started happening every time we ran dotnet tool restore. So this is sort of a "regression" for us because our in-house NuGet repo (cloudsmith) returns 404 if there are no active packages in a version range.

I think it makes sense to gracefully skip any missing leaf pages. We are already allowing 404's with the IgnoreNotFounds = true, flag. So I think not throwing an exception in a recoverable situation makes more sense here and it would help resolve our issue as well.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@mukunku mukunku requested a review from a team as a code owner April 5, 2024 19:13
@dotnet-policy-service dotnet-policy-service bot added the Community PRs created by someone not in the NuGet team label Apr 5, 2024
@mukunku
Copy link
Author

mukunku commented Apr 5, 2024

@dotnet-policy-service agree company="StackOverflow"

{
throw new InvalidDataException(registrationUri.AbsoluteUri);
log.LogDebug($"{rangeUri} returned 404 NotFound. No versions in this range are available.");
Copy link
Member

Choose a reason for hiding this comment

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

Why does the server return a leaf page that 404s?
I think that'd be bad data, so I'm not sure we should continue quietly.

You mentioned 7532d57 had the first bug.

Do you know what was the behavior in 5.6 before this change?

Copy link
Author

@mukunku mukunku Apr 5, 2024

Choose a reason for hiding this comment

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

No not sure how it behaved before that. It 404's because all the versions within the leaf have been unlisted at some point. I can't comment on why cloudsmith opts to 404 when there are no active versions in a range but just based on the IgnoreNotFound flag that's being set here, I feel like this is a valid way of handling this maybe?

Copy link
Author

Choose a reason for hiding this comment

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

I can force cloudsmith to synchronize at least one package from the range that 404's by explicitly installing an older version. That fixes those urls so they don't 404 for me but I feel like this behavior change between .net sdk 6 and .net sdk 8 is not desirable. Whether that's NuGet's responsibility I'm not sure but this seemed like a reasonable implementation to me.

Copy link
Member

Choose a reason for hiding this comment

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

It 404's because all the versions within the leaf have been unlisted

I think there's a couple of things that kind of seem incorrect.

  • Registration should not be filtering unlisted packages.
  • If all packages from a package don't "exist", then the page should not exist either.

In general, I think this change won't really lead to any issues with current servers, since most servers won't have empty pages, but it still feels like this should be a server side fix.

Copy link
Author

Choose a reason for hiding this comment

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

We tried but couldn't find any way to disable this behavior on the Cloudsmith side. Since we have a workaround in place and this isn't a blocker for us I'm happy to change this PR to just check the correct variable if that's what we want. But I still think this change makes sense in terms of defensive programming.

Copy link
Member

Choose a reason for hiding this comment

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

I think the check on line 124 makes sense. Currently it's checking the wrong value.

I'm not sure I'd call continue instead of throwing defensive programming. There's a client/server contract and the server is not honoring it. Throwing is a controlled failure.

Copy link
Author

@mukunku mukunku Apr 8, 2024

Choose a reason for hiding this comment

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

If we're going to consider this a data contract error would it make sense to set IgnoreNotFounds to false ?

Not sure why we're handling 404 differently in this case. We can treat it like any other http error code.

Copy link
Author

Choose a reason for hiding this comment

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

@nkolev92 Let me know what you think of my latest changes.

I set IgnoreNotFounds to false and adjusted my unit test accordingly. I also removed the null check since we ensure a successful http status code in the http handler.

Copy link
Author

Choose a reason for hiding this comment

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

@nkolev92 Any thoughts on the latest version of the code?

@mukunku mukunku requested a review from nkolev92 April 8, 2024 20:37
@dotnet-policy-service dotnet-policy-service bot added Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed and removed Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed labels Apr 15, 2024
@mukunku mukunku changed the title Fix NRE and Allow Missing Registration Page Leaves Fix NRE and Disallow Missing Registration Page Leaves Apr 24, 2024
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label May 7, 2024
@jeffkl jeffkl removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jun 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jul 2, 2024
@mukunku
Copy link
Author

mukunku commented Jul 22, 2024

Seems like folks don't like my fix so going to close this out.

@mukunku mukunku closed this Jul 22, 2024
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PRs created by someone not in the NuGet team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NRE When Package Metadata CatalogPage Leaf returns 404
3 participants