diff --git a/client/container_stats.go b/client/container_stats.go index 6a4b1c3b6c..277769dbff 100644 --- a/client/container_stats.go +++ b/client/container_stats.go @@ -43,6 +43,8 @@ type ContainerStatsResult struct { // ContainerStats retrieves live resource usage statistics for the specified // container. The caller must close the [io.ReadCloser] in the returned result // to release associated resources. +// +// The underlying [io.ReadCloser] is automatically closed if the context is canceled, func (cli *Client) ContainerStats(ctx context.Context, containerID string, options ContainerStatsOptions) (ContainerStatsResult, error) { containerID, err := trimID("container", containerID) if err != nil { @@ -68,6 +70,6 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, optio } return ContainerStatsResult{ - Body: resp.Body, + Body: newCancelReadCloser(ctx, resp.Body), }, nil } diff --git a/vendor/github.com/moby/moby/client/container_stats.go b/vendor/github.com/moby/moby/client/container_stats.go index 6a4b1c3b6c..277769dbff 100644 --- a/vendor/github.com/moby/moby/client/container_stats.go +++ b/vendor/github.com/moby/moby/client/container_stats.go @@ -43,6 +43,8 @@ type ContainerStatsResult struct { // ContainerStats retrieves live resource usage statistics for the specified // container. The caller must close the [io.ReadCloser] in the returned result // to release associated resources. +// +// The underlying [io.ReadCloser] is automatically closed if the context is canceled, func (cli *Client) ContainerStats(ctx context.Context, containerID string, options ContainerStatsOptions) (ContainerStatsResult, error) { containerID, err := trimID("container", containerID) if err != nil { @@ -68,6 +70,6 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, optio } return ContainerStatsResult{ - Body: resp.Body, + Body: newCancelReadCloser(ctx, resp.Body), }, nil }