-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Avoid concurrent write corruption to /etc/hosts #6893
Conversation
* Add a mutex around /etc/hosts updates (for a little extra safety) * Don't write unchanged files * Recover from out-of-sequence guard lines * Add tests Thanks to granular-ryanbonham for the suggestions & finding the issue!
When we have multiple writers racing to write /etc/hosts, we could have file corruption where we see a mix of both files. We can't use a traditional atomic file write, because we are bind-mounting /etc/hosts. Instead we write to /etc/hosts, pause, then re-read the contents. If the contents don't match, we repeat. This will not result in fair queuing, but will avoid corruption.
Builds on #6885 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good solution/work around for me. Thanks @justinsb!
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: justinsb, mikesplain The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
1 similar comment
/retest |
/test pull-kops-e2e-kubernetes-aws |
Not sure how I removed the lgtm but... Thanks @justinsb! |
…ck-of-#6893-upstream-release-1.12 Cherry pick of #6893 upstream release 1.12
When we have multiple writers racing to write /etc/hosts, we could
have file corruption where we see a mix of both files.
We can't use a traditional atomic file write, because we are
bind-mounting /etc/hosts.
Instead we write to /etc/hosts, pause, then re-read the contents. If
the contents don't match, we repeat. This will not result in fair
queuing, but will avoid corruption.