certificate: Fix deadlock in Store.Get
This commit is contained in:
parent
b38311da00
commit
688e7e2823
@ -106,7 +106,6 @@ func (s *Store) write(scope string, cert tls.Certificate) error {
|
|||||||
// Get is suitable for use in a gemini.Server's GetCertificate field.
|
// Get is suitable for use in a gemini.Server's GetCertificate field.
|
||||||
func (s *Store) Get(hostname string) (*tls.Certificate, error) {
|
func (s *Store) Get(hostname string) (*tls.Certificate, error) {
|
||||||
s.mu.RLock()
|
s.mu.RLock()
|
||||||
defer s.mu.RUnlock()
|
|
||||||
_, ok := s.scopes[hostname]
|
_, ok := s.scopes[hostname]
|
||||||
if !ok {
|
if !ok {
|
||||||
// Try wildcard
|
// Try wildcard
|
||||||
@ -121,10 +120,11 @@ func (s *Store) Get(hostname string) (*tls.Certificate, error) {
|
|||||||
_, ok = s.scopes["*"]
|
_, ok = s.scopes["*"]
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
|
s.mu.RUnlock()
|
||||||
return nil, errors.New("unrecognized scope")
|
return nil, errors.New("unrecognized scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
cert := s.certs[hostname]
|
cert := s.certs[hostname]
|
||||||
|
s.mu.RUnlock()
|
||||||
|
|
||||||
// If the certificate is empty or expired, generate a new one.
|
// If the certificate is empty or expired, generate a new one.
|
||||||
if cert.Leaf == nil || cert.Leaf.NotAfter.Before(time.Now()) {
|
if cert.Leaf == nil || cert.Leaf.NotAfter.Before(time.Now()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user