Commit Graph

5 Commits

Author SHA1 Message Date
Matthew Holt
93a28b732a
Make cache options updateable; new remove methods
These are useful for advanced applications (like Caddy) which would
like to remove certificates from the
cache in a controlled way, and operate the
cache with new settings while running.
2023-07-08 09:56:51 -06:00
Matthew Holt
cbeee6e6b2
A few tweaks and fixes 2020-02-24 12:23:54 -07:00
Matt Holt
8f7a1caa59
Significant refactoring to improve correctness and flexibility (#39)
* Significant refactor

This refactoring expands the capabilities of the library for advanced
use cases, as well as improving the overall architecture, including
possible memory leak fixes if used over a long period with many certs
loaded into memory. This refactor enables using different configs
depending on the certificate.

The public API has changed slightly, however, and arguably it is
slightly less convenient/elegant. I have never quite found the perfect
design for this package, and this certainly isn't it, but I think it's
better than what we had before.

There is still work to be done, but this is a good step forward. I've
decoupled Storage from Cache, and made it easier and more correct for
Configs (and Storage values) to be short-lived. Cache is the only value
that should be long-lived.

Note that CertMagic no longer automatically takes care of storage (i.e.
it used to delete old OCSP staples, but now it doesn't). The functions
to do this are still there and even exported, and now we expect the
application to call the cleanup functions when it wants to.

* Fix little oopsies

* Create Manager abstraction so obtain/renew isn't limited to ACME
2019-04-20 10:44:55 -06:00
Matt Holt
a3b276a1b4
storage: Replace TryLock and Wait with Lock; simplify FileStorage
* Replace TryLock and Wait with Lock, and check for idempotency (issue #5)

* Fix logic of lock waiter creation in FileStorage (+ improve client log)

* Return from Wait() if lock file becomes stale

* Remove racy deletion of empty lock folder

* move all (FileStorage) methods to (*FileStorage) so assignments to fields like fileStorageNameLocks aren't lost

* rework lock acquisition

* Create lockDir just before lock file creation to reduce the chance that another process calls Unlock() and removes lockDir while we were waiting, preventing us from creating the lock file.
* Use the same strategy that Wait() uses to avoid depending on internal state.

* fix unlock of unlocked mutex

* Move fileStorageNameLocksMu into FileStorage struct

* implement new lockfile removal strategy and simplify the lock acquisition loop.

* readme: Add link to full examples

* Rework file lock obtaining and waiting logic

* Remove not-useful optimization to simplify file-locking logic
2018-12-19 14:25:11 -07:00
Matthew Holt
318e24ccb2
Print which cache is doing maintenance in log entries 2018-12-12 15:43:34 -07:00