Skip to content

distribution: fix / improve handling of "closed pipe" and context cancellation / timeouts#49297

Merged
vvoland merged 2 commits intomoby:masterfrom
thaJeztah:distribution_improve_context_and_pipe_errs
Jan 22, 2025
Merged

distribution: fix / improve handling of "closed pipe" and context cancellation / timeouts#49297
vvoland merged 2 commits intomoby:masterfrom
thaJeztah:distribution_improve_context_and_pipe_errs

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

distribution/utils: WriteDistributionProgress simplify check for broken pipe

The isBrokenPipe utility was added in 3d86b0c
to unwrap the error returned to detect if it was a broken pipe error.
net.OpError now implements Unwrap(), so we can simplify this check
using errors.Is.

distribution: continueOnError: handle context cancellation / timeout

Before this change, it would fail to detect context errors, resulting in
pullEndpoints clobbering the context error and changing it into a fallback
error;

moby/distribution/pull.go

Lines 114 to 119 in 0299335

if _, ok := err.(fallbackError); !ok && continueOnError(err, endpoint.Mirror) {
err = fallbackError{
err: err,
transportOK: true,
}
}

While the context cancellation would still be handled, the error returned
would be wrapped, causing calling code to no longer being able to detect
it as context cancellation;

case <-ctx.Done():

Context cancellation are now logged as "info" in daemon-logs, as they
are not an error from the daemon's perspective;

Before:

DEBU[2025-01-18T14:59:10.079259676Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2"
ERRO[2025-01-18T14:59:10.564076135Z] Not continuing with pull after error: context canceled

After:

DEBU[2025-01-18T15:09:56.743045420Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2"
INFO[2025-01-18T15:09:57.390835628Z] Not continuing with pull after error          error="context canceled"

This package needs a big cleanup for context- and error-handling, as it's
very messy, so these changes are only a short-term workaround.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah added area/distribution Image Distribution status/2-code-review kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. labels Jan 18, 2025
@thaJeztah thaJeztah added this to the 28.0.0 milestone Jan 18, 2025
…en pipe

The isBrokenPipe utility was added in 3d86b0c
to unwrap the error returned to detect if it was a broken pipe error.
`net.OpError` now implements Unwrap(), so we can simplify this check
using `errors.Is`.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Before this change, it would fail to detect context errors, resulting in
pullEndpoints clobbering the context error and changing it into a fallback
error; https://github.com/moby/moby/blob/029933578be8070181d956a825e605c904f1865b/distribution/pull.go#L114-L119

While the context cancellation would still be handled, the error returned
would be wrapped, causing calling code to no longer being able to detect
it as context cancellation;
https://github.com/moby/moby/blob/029933578be8070181d956a825e605c904f1865b/distribution/pull.go#L125

Context cancellation are now logged as "info" in daemon-logs, as they
are not an error from the daemon's perspective;

Before:

    DEBU[2025-01-18T14:59:10.079259676Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2"
    ERRO[2025-01-18T14:59:10.564076135Z] Not continuing with pull after error: context canceled

After:

    DEBU[2025-01-18T15:09:56.743045420Z] pulling blob "sha256:8bb55f0677778c3027fcc4253dc452bc9c22de989a696391e739fb1cdbbdb4c2"
    INFO[2025-01-18T15:09:57.390835628Z] Not continuing with pull after error          error="context canceled"

This package needs a big cleanup for context- and error-handling, as it's
very messy, so these changes are only a short-term workaround.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the distribution_improve_context_and_pipe_errs branch from 07fd767 to 5277415 Compare January 18, 2025 15:21
@thaJeztah thaJeztah self-assigned this Jan 20, 2025
@thaJeztah thaJeztah requested a review from vvoland January 20, 2025 10:56
@vvoland vvoland merged commit a5960d4 into moby:master Jan 22, 2025
@thaJeztah thaJeztah deleted the distribution_improve_context_and_pipe_errs branch January 22, 2025 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/distribution Image Distribution kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants