High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
fix: protect SES cert cache map with sync.RWMutex to prevent concurrent map writes crash (#3050)
Abdulazez (Abza)7a751ce70f2e
diff --git a/internal/bounce/webhooks/ses.go b/internal/bounce/webhooks/ses.goindex 387b6178..e510f034 100644--- a/internal/bounce/webhooks/ses.go+++ b/internal/bounce/webhooks/ses.go@@ -13,6 +13,7 @@ import ("net/url""regexp""strings"+ "sync""time""github.com/knadh/listmonk/models"@@ -65,6 +66,7 @@ type sesMail struct {// SES handles SES/SNS webhook notifications including confirming SNS topic subscription// requests and bounce notifications.type SES struct {+ mu sync.RWMutexcerts map[string]*x509.Certificate}@@ -224,7 +226,10 @@ func (s *SES) getCert(certURL string) (*x509.Certificate, error) {}// Return if it's cached.- if c, ok := s.certs[u.Path]; ok {+ s.mu.RLock()+ c, ok := s.certs[u.Path]+ s.mu.RUnlock()+ if ok {return c, nil}@@ -252,7 +257,18 @@ func (s *SES) getCert(certURL string) (*x509.Certificate, error) {cert, err := x509.ParseCertificate(p.Bytes)// Cache the cert in-memory.- s.certs[u.Path] = cert+ s.mu.Lock()+ // Check again if another goroutine already cached it while we were fetching.+ if c2, ok := s.certs[u.Path]; ok && c2 != nil {+ s.mu.Unlock()+ // Return the cached cert and ignore this goroutine's parse error (if any).+ return c2, nil+ }+ // Only cache when parsing succeeded (don't cache nil certs from failures).+ if err == nil {+ s.certs[u.Path] = cert+ }+ s.mu.Unlock()return cert, err}