lib/utils/fs.go: Do not remove lockfiles on Windows #21655
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #21529.
Removing auxiliary lockfiles was added in #16364. Back then we decided to remove lockfiles on unlock because leaving them behind could be confusing for users.
After #19420 was merged, Connect was creating dozens of locks for
known_hosts
. It turns out that repeatedly deletingknown_hosts.lock
was causingflock.Flock.TryRLock
to return either "access denied" or "The process cannot access the file because it is being used by another process" (see #21529). Getting rid of lockfile cleanup on unlock solves this problem.This PR also changes the suffix of auxiliary lockfiles from
.lock
to.lock.tmp
to hopefully help users understand that those leftovers don't really affect the execution of tsh, unlike for example git'sindex.lock
.At the moment, the file lock functions from
lib/utils/fs.go
are used in:lib/client/trusted_certs_store.go
lib/events/filesessions
lib/tbot/config
This change will only have an impact on the first location, leaving
known_hosts.lock.tmp
on Windows, as bothteleport
andtbot
binaries are not available for Windows.