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

overlay differ: cancel diff calculation cleanly #2662

Merged
merged 1 commit into from
Mar 3, 2022

Conversation

ktock
Copy link
Collaborator

@ktock ktock commented Feb 21, 2022

Fixes #2655

This commit fixes that exporting layers doesn't cancelled cleanly.

master version:

#7 exporting layers
#7 exporting layers 2.5s done
#7 ERROR: missing lease requirement for setBlob
------
 > exporting to oci image format:
------
error: failed to solve: Canceled: context canceled```

PR version:

#7 exporting layers
#7 exporting layers 2.7s done
#7 CANCELED
error: failed to solve: Canceled: context canceled

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

This looks weird to me. Why isn't the Changes already returning the correct error? We should not need to handle the cases where err == nil . If err == nil that means that there is no error and cw.Close() should be called (even if context is canceled it was too late). If Changes returns early because context got canceled then it should always return with an error.

@ktock
Copy link
Collaborator Author

ktock commented Feb 22, 2022

@tonistiigi

Why isn't the Changes already returning the correct error?

This seems because fs.ChangeFunc is agnostic about context cancellation. Fixed to propagate context cancellation to Change via the underlying writer.

if err := changeFn(kind, path, f, nil); err != nil {

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

Can you point me to where this error is returned that is created because of context is canceled but the error itself does not match canceled error.

@@ -40,9 +41,12 @@ func (sr *immutableRef) tryComputeOverlayBlob(ctx context.Context, lower, upper
if err != nil {
return emptyDesc, false, errors.Wrap(err, "failed to open writer")
}
var openErr error // can be set before closing writer. This can be used to make sure the writer is closed.
Copy link
Member

Choose a reason for hiding this comment

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

cleaner way to do this would be to set cw = nil after it has been closed and add a nil check if the defer. I'm not sure I understand how this is related to the issue though.

@ktock
Copy link
Collaborator Author

ktock commented Feb 22, 2022

@tonistiigi

On master version of BuildKit,fs.ChangeFunc is agnostic about context cancellation so doesn't return an error even when context is cancelled and it continues its execution.
This patch tries to make it cancellation-aware.

In the following example of master version BuildKit, code execution doesn't terminate until it encounters missing lease requirement for setBlob error in setBlob, even when sending a signal.

FROM registry2-buildkit:5000/ubuntu:20.04-org
RUN head -c 100MB </dev/urandom > /sample
# buildctl build --progress=plain --frontend=dockerfile.v0 --local context=/tmp/ctx1 --local dockerfile=/tmp/ctx1 \
               --output type=oci,dest=/tmp/out.tar
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile:
#1 transferring dockerfile: 125B done
#1 DONE 0.2s

#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.2s

#3 [internal] load metadata for registry2-buildkit:5000/ubuntu:20.04-org
#3 DONE 0.1s

#4 [auth] sharing credentials for registry2-buildkit:5000
#4 DONE 0.0s

#5 [1/2] FROM registry2-buildkit:5000/ubuntu:20.04-org@sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d
#5 resolve registry2-buildkit:5000/ubuntu:20.04-org@sha256:adf73ca014822ad8237623d388cedf4d5346aa72c270c5acc01431cc93e18e2d 0.0s done
#5 sha256:5e9250ddb7d0fa6d13302c7c3e6a0aa40390e42424caed1e5289077ee4054709 187B / 187B 0.0s done
#5 sha256:57671312ef6fdbecf340e5fed0fb0863350cd806c92b1fdd7978adbd02afc5c3 851B / 851B 0.0s done
#5 sha256:345e3491a907bb7c6f1bdddcf4a94284b8b6ddd77eb7d93f09432b17b20f2bbe 28.54MB / 28.54MB 0.1s done
#5 extracting sha256:345e3491a907bb7c6f1bdddcf4a94284b8b6ddd77eb7d93f09432b17b20f2bbe
#5 extracting sha256:345e3491a907bb7c6f1bdddcf4a94284b8b6ddd77eb7d93f09432b17b20f2bbe 0.8s done
#5 extracting sha256:57671312ef6fdbecf340e5fed0fb0863350cd806c92b1fdd7978adbd02afc5c3 0.0s done
#5 extracting sha256:5e9250ddb7d0fa6d13302c7c3e6a0aa40390e42424caed1e5289077ee4054709 0.0s done
#5 DONE 0.0s

#6 [2/2] RUN head -c 100MB </dev/urandom > /sample
#6 DONE 0.9s

#7 exporting to oci image format
#7 exporting layers
  C-c C-c
#7 exporting layers 2.5s done
#7 ERROR: missing lease requirement for setBlob
------
 > exporting to oci image format:
------
error: failed to solve: Canceled: context canceled

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
@tonistiigi tonistiigi merged commit d1a8f13 into moby:master Mar 3, 2022
@ktock ktock deleted the overlayfs-differ-cancel branch March 3, 2022 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v0.10] exporting does not cancel cleanly with overlay differ
2 participants