Skip to content

cli/config/configfile: Atomically rewrite the config file when saving.#1359

Merged
thaJeztah merged 1 commit into
docker:masterfrom
tsuna:master
Sep 11, 2018
Merged

cli/config/configfile: Atomically rewrite the config file when saving.#1359
thaJeztah merged 1 commit into
docker:masterfrom
tsuna:master

Conversation

@tsuna
Copy link
Copy Markdown
Contributor

@tsuna tsuna commented Sep 10, 2018

The config file was being truncated first, which created a window during
which it was empty, causing concurrent uses of the docker command to
potentially fail with:

WARNING: Error loading config file: /var/lib/jenkins/.docker/config.json: EOF
Error response from daemon: Get https://registry/v2/foo/manifests/latest: no basic auth credentials

Signed-off-by: Benoit Sigoure tsunanet@gmail.com

- Description for the changelog

The use of commands that change the Docker CLI config (e.g. docker login) concurrently with other commands could lead to the other commands not being able to read the configuration.

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

🐹

The config file was being truncated first, which created a window during
which it was empty, causing concurrent uses of the `docker` command to
potentially fail with:
  WARNING: Error loading config file: /var/lib/jenkins/.docker/config.json: EOF
  Error response from daemon: Get https://registry/v2/foo/manifests/latest: no basic auth credentials

Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>
@tsuna
Copy link
Copy Markdown
Contributor Author

tsuna commented Sep 10, 2018

Seems like others have run into this before me as well: https://issues.jenkins-ci.org/browse/JENKINS-44228

@jwatte
Copy link
Copy Markdown

jwatte commented Sep 10, 2018

I for one would like to be the first to welcome our new atomic file writing overlords!

@tsuna
Copy link
Copy Markdown
Contributor Author

tsuna commented Sep 10, 2018

The build failed due to some unrelated failure in an early apt-get update step.

@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #1359 into master will increase coverage by 0.05%.
The diff coverage is 55.55%.

@@            Coverage Diff             @@
##           master    #1359      +/-   ##
==========================================
+ Coverage   54.63%   54.69%   +0.05%     
==========================================
  Files         293      293              
  Lines       19369    19374       +5     
==========================================
+ Hits        10582    10596      +14     
+ Misses       8126     8111      -15     
- Partials      661      667       +6

assert.NilError(t, err)
cfg, err := ioutil.ReadFile("test-save")
assert.NilError(t, err)
assert.Check(t, is.Equal(string(cfg), "{\n \"auths\": {}\n}"))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Feels like an omitempty tag is missing in the Auths field.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can fix in another PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Review after merge (so maybe for the just opened follow-up) 😅:
You can use backquotes instead:

assert.Check(t, is.Equal(string(cfg), `{
	"auths": {}
}`))

Copy link
Copy Markdown
Collaborator

@tiborvass tiborvass left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐯

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

left one comment; I'll quickly check with @vdemeester if he thinks we should address before merging 👍

os.Remove(temp.Name())
return err
}
return os.Rename(temp.Name(), configFile.Filename)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit; if the rename fails we'll leave behind the temp file.

Chances are probably slim that that happens, so I'm ok with keeping this as-is (we can do a follow-up if we think that's a concern)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I feel it's not that big of a deal, so I'm ok keeping as-is and do a follow-up if we need 👼

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

alrighty; let's get this merged; thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Excellent catch! Fixed in #1366 since this one already sailed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants