setupHijackConn only closed the response body when the upgrade failed.
otelhttp ends its client span when the body is closed, so the span of
every successful ContainerAttach, ContainerExecAttach and DialHijack
call was never ended. A 101 response has no body, so closing it does not
touch the hijacked connection.
Signed-off-by: berce <75228263+bercedev@users.noreply.github.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Replace the rapid-based property test for plugin capability IDs
with a table-driven test and Go's built-in fuzzing support.
Preserve the comparison against the historical JSON parser to
catch compatibility regressions, and add explicit test cases for
the supported serialization formats and invalid inputs.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Use tls.Dialer.DialContext so connection setup and the TLS handshake
honor the caller's cancellation and deadline. Preserve TLS verification
and leave established connections independent of the dial context.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Close the dialed connection when the request context is canceled while
writing the upgrade request or waiting for the response. Stop the
cancellation callback before handing a successful connection to the caller,
and wait for an in-flight callback so a closed connection is never returned.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Add WithHTTPRequestHook to allow callers to inspect outgoing HTTP requests
and modify request metadata before they are sent to the daemon.
Request hooks receive a clone of the original request so that modifications
made by hooks do not mutate the request passed to the client's RoundTripper.
Changes made by hooks are preserved on the request passed to the underlying
transport.
Protect request bodies while hooks are running, preventing hooks from reading
or closing the body while restoring the original body before the request is
sent. Hooks are invoked in registration order and may return an error to abort
the request.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Response hooks are stored in the client's configuration and are not
modified after the client is constructed.
Use the configured slice directly when constructing hookTransport
instead of creating an unnecessary copy.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Response hooks added in 2bc7febeb6 ("client: Add HTTP response
hooks") are only installed on the client's HTTP transport.
Hijacked requests use a separate transport and therefore bypass the
configured response hooks.
Wrap the hijack transport with hookTransport so response hooks are
also invoked for the HTTP upgrade response, and add coverage for the
hijack path.
updates 2bc7febeb6
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Response hooks are documented not to read or close the response body, but
currently receive the original response and can therefore consume or close
the body before it is returned to the caller.
Pass hooks a shallow copy of the response with an unreadable body whose Close
method is a no-op. This preserves access to response metadata while preventing
hooks from affecting the body returned to the caller.
Add coverage to verify that attempts to read the body fail and closing it from
a hook does not close the underlying response body.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
follow-up to b20c3db932, which updated other
request-methods that took a body, but didn't update this one.
updates b20c3db932
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Use []plugin.Privilege for internal plugin install and upgrade helpers instead
of the exported plugin.Privileges type.
The latter primarily exists to implement sort.Interface, which these callers
do not use. Keep plugin.Privileges at the public API boundary, where it remains
part of AcceptPermissionsFunc's signature.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add WithMessagePrinter to allow callers of DisplayStream and
DisplayMessages to customize presentation of non-auxiliary messages.
The custom printer replaces the default terminal-aware rendering, allowing
callers to handle progress output, terminal sizing, and message errors as
needed. Auxiliary messages continue to use WithAuxCallback.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
A container that defines no stop timeout of its own always got 10
seconds on Linux, or 30 on Windows, to shut down before being killed.
The value was a constant in the container package, so operators who
wanted a different grace period had to pass `--stop-timeout` on every
container.
Add a `default-stop-timeout` daemon flag and configuration file option
that supplies that fallback. Stopping a container, killing it, and
computing the daemon shutdown timeout take the value from the daemon
configuration when the container has no timeout of its own, so an
explicit per-container timeout still wins and the container
configuration itself stays untouched. The option can be reloaded, and
negative values are rejected.
mergo cannot tell an unset option from a zero value, so a configured
timeout of `0`, meaning "kill immediately", would be replaced by the
non-zero flag default while merging. Remember whether the
configuration file set the option, and restore its value after the
merge.
`ContainerConfig.StopTimeout` in the API documentation no longer
claims a fixed default of 10 seconds, because the fallback is now
whatever `default-stop-timeout` holds.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
The project was sunset;
> After more than a decade of serving the ecosystem, the time
> has come to sunset Go Report Card. Following the loss of our
> primary infrastructure sponsor, maintaining the web app is
> no longer sustainable.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before this patch, the Task and Plugin placement would contain "unkown/unknown"
platforms and duplicates. Swarm currently only supports os/arch for placement
preferences, but images often provide variants that differ in Variant, OSVersion
and OSFeatures. These duplicates unlikely caused issues in practice, but made
the service spec more verbose;
docker service inspect --format '{{json .Spec.TaskTemplate.Placement.Platforms}}' foo
[
{"Architecture":"amd64","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"Architecture":"arm64","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"Architecture":"386","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"Architecture":"ppc64le","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"Architecture":"riscv64","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"},
{"Architecture":"s390x","OS":"linux"},
{"Architecture":"unknown","OS":"unknown"}
]
Update the imageDigestAndPlatforms utility to filter out "unknown"
platforms and to remove duplicates.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
The default is to not insert defaults, so we can skip if it's not
set; this also removes a fmt.Sprintf that wasn't needed.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>