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

chunked: add check for more parts #2160

Closed
wants to merge 1 commit into from

Conversation

giuseppe
Copy link
Member

@giuseppe giuseppe commented Nov 5, 2024

validate that there are no other parts returned by the client, and do not ignore other errors that could have happened later.

Copy link
Contributor

openshift-ci bot commented Nov 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Nov 5, 2024
validate that there are no other parts returned by the client, and do
not ignore other errors that could have happened later.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the chunked-consume-channels branch from 75717e2 to cf619cf Compare November 5, 2024 13:40
Copy link
Contributor

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

It'd be useful to have a bit more context about this - did you find this through code auditing or did it come out of a user hitting it in reality?

@@ -1176,6 +1202,10 @@ func (c *chunkedDiffer) copyAllBlobToFile(destination *os.File) (digest.Digest,
// copy the entire tarball and compute its digest
_, err = io.CopyBuffer(destination, r, c.copyBuffer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Aren't we ignoring this error now?

err = err1
}
}
if closed == 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused why we have this counter instead of checking err and err1

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

I think this doesn’t quite work as is, and https://issues.redhat.com/browse/OCPBUGS-43968 suggests that we need either a redesign or a much more careful error handling.


Also, unless the code becomes somehow trivial, I think the consumption of (streams, errs), starting with the first select already, should be strongly centralized in a helper, not copy&pasted. (We do have some helpers, but those are already copy&pasted instead of used universally.)

select {
case _, ok := <-streams:
if !ok {
closed++
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICS once this happens, this case will always trigger and this function will consume 100% of a CPU until the other channel is closed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

… and close will keep incrementing.

case _, ok := <-streams:
if !ok {
closed++
} else if err == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nothing guarantees that we read the error from errs before we read from this channel. select is explicitly designed to choose randomly.

@giuseppe
Copy link
Member Author

giuseppe commented Nov 5, 2024

I close this PR for now. I'll redesign to address https://issues.redhat.com/browse/OCPBUGS-43968

@giuseppe giuseppe closed this Nov 5, 2024
@giuseppe
Copy link
Member Author

giuseppe commented Nov 6, 2024

alternative fix: #2162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants