v0.01: 修复死锁Bug + DNS-01默认 + 超时调整

This commit is contained in:
2026-05-13 10:58:29 +08:00
parent 3fa77d9bc0
commit a9842e9212
7 changed files with 114 additions and 51 deletions
+15 -10
View File
@@ -43,9 +43,9 @@ func Load() *Config {
// CertStore is the in-memory store for certificates with file persistence
type CertStore struct {
mu sync.RWMutex
data map[string]*Certificate // key: domain
path string
mu sync.RWMutex
data map[string]*Certificate // key: domain
path string
nextID uint
}
@@ -99,11 +99,9 @@ func (s *CertStore) Load() error {
return nil
}
// Save writes the current in-memory certificates to JSON file
func (s *CertStore) Save() error {
s.mu.RLock()
defer s.mu.RUnlock()
// save writes the current in-memory certificates to JSON file
// IMPORTANT: caller must hold the lock (read or write) before calling this
func (s *CertStore) save() error {
certs := make([]*Certificate, 0, len(s.data))
for _, c := range s.data {
certs = append(certs, c)
@@ -117,6 +115,13 @@ func (s *CertStore) Save() error {
return os.WriteFile(s.path, data, 0600)
}
// Save writes the current in-memory certificates to JSON file (public, acquires own lock)
func (s *CertStore) Save() error {
s.mu.RLock()
defer s.mu.RUnlock()
return s.save()
}
// GetAll returns all certificates sorted by ID descending
func (s *CertStore) GetAll() []*Certificate {
s.mu.RLock()
@@ -170,7 +175,7 @@ func (s *CertStore) Upsert(cert *Certificate) error {
cert.UpdatedAt = time.Now()
s.data[cert.Domain] = cert
return s.Save()
return s.save()
}
// Delete removes a certificate by ID
@@ -181,7 +186,7 @@ func (s *CertStore) Delete(id uint) error {
for domain, c := range s.data {
if c.ID == id {
delete(s.data, domain)
return s.Save()
return s.save()
}
}
return nil