-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store: serialise access with a file lock
Previously the code attempts to use ioutils.AtomicWriteFile to update meta.json but this fails on Windows if another process has the meta.json open for reading (unlike on Unix OSes). Example error: ``` rename C:\Users\docker\.docker\contexts\meta\<id>\.tmp-meta.json2945721760 C:\Users\docker\.docker\contexts\meta\<id>\meta.json: Access is denied. ``` So if one `docker context inspect` is running, then another `docker context` command can fail transiently in `CreateOrUpdate`. Avoid this problem by serialising accesses to the context filesystem db using a lock file via github.com/gofrs/flock which uses LockFileEx on Windows and syscall.Flock on Unix. The lock is associated with a file descriptor / handle and released by calling Close() or when the process exits. Note this means that functions which could previously fail for one reason can now fail for two (the original + a lock/unlock failure). Use go-multierror to return all the errors. When we upgrade to go 1.20 we can use errors.Join. Signed-off-by: David Scott <dave.scott@docker.com>
- Loading branch information
Showing
3 changed files
with
107 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters