certmagic icon indicating copy to clipboard operation
certmagic copied to clipboard

Use posix file advisory locks on supported platforms

Open elee1766 opened this issue 8 months ago • 1 comments

the current storage implementation uses a home brew approach to locking a file for a specific process.

this is a feature built into posix compatible filesystems.

certmagic filestorage should capability detect if posix locks are available, and if they are, use them to protect access to files.

advisory locks have two major weaknesses, that users of sqlite, mdbx, lmdb, are probably well familiar with.

  1. they do not work well on network filesystems (depends on implementation, very flaky regardless)
  2. you cannot use them to lock within a process - you still need mutex in process code to protect access to it.

#1 already exists as an issue in the current implementation

#2 can easily be dealt with by go's mutex.

as a result, I think that it would be good to incorporate this feature into certmagic storage.

that said, I don't use the filesystem module in production, so I don't really care that much. maybe someone who does would be happy to do this work :)

some resources:

https://gavv.net/articles/file-locks/ https://github.com/juju/fslock

elee1766 avatar Jun 21 '24 01:06 elee1766