This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch refactor-with-go
in repository https://gitbox.apache.org/repos/asf/dubbo-admin.git


The following commit(s) were added to refs/heads/refactor-with-go by this push:
     new 8e287270 fix unlock in refresh server cert (#1068)
8e287270 is described below

commit 8e28727061cbe9b0b919837436f326f626d61cfb
Author: Jun <[email protected]>
AuthorDate: Wed Mar 29 16:47:00 2023 +0800

    fix unlock in refresh server cert (#1068)
---
 pkg/authority/cert/storage.go | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/pkg/authority/cert/storage.go b/pkg/authority/cert/storage.go
index aad9a5eb..31c8bd4e 100644
--- a/pkg/authority/cert/storage.go
+++ b/pkg/authority/cert/storage.go
@@ -162,16 +162,18 @@ func (s *storageImpl) RefreshServerCert() {
                }
 
                time.Sleep(time.Duration(interval) * time.Millisecond)
-               s.mutex.Lock()
-               if s.authorityCert == nil || !s.authorityCert.IsValid() {
-                       // ignore if authority cert is invalid
-                       continue
-               }
-               if s.serverCerts == nil || !s.serverCerts.IsValid() {
-                       logger.Sugar().Infof("Server cert is invalid, refresh 
it.")
-                       s.serverCerts = SignServerCert(s.authorityCert, 
s.serverNames, s.certValidity)
-               }
-               s.mutex.Unlock()
+               func() {
+                       s.mutex.Lock()
+                       defer s.mutex.Unlock()
+                       if s.authorityCert == nil || !s.authorityCert.IsValid() 
{
+                               // ignore if authority cert is invalid
+                               return
+                       }
+                       if s.serverCerts == nil || !s.serverCerts.IsValid() {
+                               logger.Sugar().Infof("Server cert is invalid, 
refresh it.")
+                               s.serverCerts = SignServerCert(s.authorityCert, 
s.serverNames, s.certValidity)
+                       }
+               }()
        }
 }
 

Reply via email to