Skip to content

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

Merged
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:carry_3845
Dec 6, 2022
Merged

Fix bug where incorrect response is returned [carry 3845]#3901
thaJeztah merged 1 commit into
docker:masterfrom
thaJeztah:carry_3845

Conversation

@thaJeztah

@thaJeztahthaJeztah commented Dec 5, 2022

Copy link
Copy Markdown
Member

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 threadcmd/docker/docker.go
Comment on lines +422 to +423
si := details.ServerInfo()
if ost, ok := curr.Annotations["ostype"]; ok && si.OSType != "" && ost != si.OSType {

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

codecov-commenter commented Dec 5, 2022

Copy link
Copy Markdown

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
thaJeztahforce-pushed the carry_3845 branch 7 times, most recently from 07c5b89 to a60a9a1CompareDecember 5, 2022 20:45
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

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.

@thaJeztah
thaJeztah marked this pull request as draft December 5, 2022 21:40
@thaJeztah
thaJeztah marked this pull request as ready for review December 6, 2022 07:27
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 <ahosavalike@ucsd.edu>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah

Copy link
Copy Markdown
MemberAuthor

Thx!

@thaJeztah
thaJeztah merged commit 8fc1444 into docker:masterDec 6, 2022
@thaJeztah
thaJeztah deleted the carry_3845 branch December 6, 2022 08:24
Comment threadcmd/docker/docker.go
}
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
Copy Markdown
MemberAuthor

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 freeto 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

@thaJeztah@codecov-commenter@vvoland@adyanth