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

Fix bug where incorrect response is returned [carry 3845] #3901

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Dec 5, 2022

When server is unreachable and docker checkpoint (or any command that needs to check the server type) is run, incorrect error was returned.

When checking if the daemon had the right OS, we compared the OSType from the clients ServerInfo(). In situations where the client cannot connect to the daemon, a "stub" Info is used for this, in which we assume the daemon has experimental enabled, and is running the latest API version.

However, we cannot fill in the correct OSType, so this field is empty in this situation.

This patch only compares the OSType if the field is non-empty, otherwise assumes the platform matches.

before this:

docker -H unix:///no/such/socket.sock checkpoint create test test
docker checkpoint create is only supported on a Docker daemon running on linux, but the Docker daemon is running on

with this patch:

docker -H unix:///no/such/socket.sock checkpoint create test test
Cannot connect to the Docker daemon at unix:///no/such/socket.sock. Is the docker daemon running?

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

Comment on lines +422 to +423
si := details.ServerInfo()
if ost, ok := curr.Annotations["ostype"]; ok && si.OSType != "" && ost != si.OSType {
Copy link
Member Author

Choose a reason for hiding this comment

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

In cases where we were not able to connect with the daemon, we set Experimental to "true", but as we don't know the daemon's OSType, we can't set that value, so in that case we should ignore these;

cli/cli/command/cli.go

Lines 342 to 343 in 7240f70

// Default to true if we fail to connect to daemon
cli.serverInfo = ServerInfo{HasExperimental: true}

We can probably optimise and detect that we didn't have a valid ping, and skip all of these checks, but leaving that for a follow-up.

@thaJeztah
Copy link
Member Author

Looks like I have one test to fix / verify;

#19 64.01 === FAIL: cmd/docker TestBuildkitDisabled (0.00s)
#19 64.01     builder_test.go:137: line 0: expected "" to end with "DEPRECATED: The legacy builder is deprecated and will be removed in a future release."
#19 64.01     builder_test.go:137:

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2022

Codecov Report

Merging #3901 (f33ef47) into master (f33ef47) will not change coverage.
The diff coverage is n/a.

❗ Current head f33ef47 differs from pull request most recent head 20ba591. Consider uploading reports for the commit 20ba591 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3901   +/-   ##
=======================================
  Coverage   59.22%   59.22%           
=======================================
  Files         287      287           
  Lines       24723    24723           
=======================================
  Hits        14641    14641           
  Misses       9197     9197           
  Partials      885      885           

@thaJeztah thaJeztah force-pushed the carry_3845 branch 7 times, most recently from 07c5b89 to a60a9a1 Compare December 5, 2022 20:45
@thaJeztah
Copy link
Member Author

Hm.. right, so the "unit" test is actually using a docker client, which tries to connect to a daemon (which isn't there);

=== FAIL: cmd/docker TestBuildkitDisabled (0.00s)
#19 76.40 ping err: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Then the check if buildkit must be used is based on the (non-existing) ping result; if that's "windows", it's okay, but it it's non-windows, then it should print an error. As (at this stage) we don't know if the daemon is windows or linux, we probably shouldn't produce an error (which is what this PR does), but the test expects that error to happen.

When server is unreachable and docker checkpoint (or any command that
needs to check the server type) is run, incorrect error was returned.

When checking if the daemon had the right OS, we compared the OSType
from the clients ServerInfo(). In situations where the client cannot
connect to the daemon, a "stub" Info is used for this, in which we
assume the daemon has experimental enabled, and is running the latest
API version.

However, we cannot fill in the correct OSType, so this field is empty
in this situation.

This patch only compares the OSType if the field is non-empty, otherwise
assumes the platform matches.

before this:

    docker -H unix:///no/such/socket.sock checkpoint create test test
    docker checkpoint create is only supported on a Docker daemon running on linux, but the Docker daemon is running on

with this patch:

    docker -H unix:///no/such/socket.sock checkpoint create test test
    Cannot connect to the Docker daemon at unix:///no/such/socket.sock. Is the docker daemon running?

Co-authored-by: Adyanth Hosavalike <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member Author

Thx!

@thaJeztah thaJeztah merged commit 8fc1444 into docker:master Dec 6, 2022
@thaJeztah thaJeztah deleted the carry_3845 branch December 6, 2022 08:24
@@ -419,10 +419,11 @@ func areSubcommandsSupported(cmd *cobra.Command, details versionDetails) error {
if cmdVersion, ok := curr.Annotations["version"]; ok && versions.LessThan(details.CurrentVersion(), cmdVersion) {
return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, details.CurrentVersion())
}
if ost, ok := curr.Annotations["ostype"]; ok && ost != details.ServerInfo().OSType {
return fmt.Errorf("%s is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s", cmd.CommandPath(), ost, details.ServerInfo().OSType)
si := details.ServerInfo()
Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, and I just realised I introduced a regression here; this was deliberately put inline to allow it to be executed conditionally (see b397391 / #2424)

Opening a PR to fix that 😅

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.

Incorrect error message when server is unreachable
4 participants