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

xuetaoli pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3929ee48f fix: release the lock in advance in case causing deadlock 
(#3238)
3929ee48f is described below

commit 3929ee48f34bab6036aaf5b22526b1b64ccf972a
Author: yangpixi <[email protected]>
AuthorDate: Fri Mar 13 11:48:39 2026 +0800

    fix: release the lock in advance in case causing deadlock (#3238)
    
    * fix: release the lock in advance in case causing deadlock
    
    * fix: add read lock for exportServices().
    
    * fix: add read lock for exportInternalServices()
    
    * fix: remove unnecessary read lock
---
 server/server.go | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/server/server.go b/server/server.go
index 271db85f4..9fde10bcd 100644
--- a/server/server.go
+++ b/server/server.go
@@ -104,10 +104,12 @@ func (s *Server) genSvcOpts(handler any, info 
*common.ServiceInfo, opts ...Servi
                return nil, errors.New("Server has not been initialized, please 
use NewServer() to create Server")
        }
        var svcOpts []ServiceOption
+
        appCfg := s.cfg.Application
        proCfg := s.cfg.Provider
        prosCfg := s.cfg.Protocols
        regsCfg := s.cfg.Registries
+
        // todo(DMwangnima): record the registered service
        // Record the registered service for debugging and monitoring
        interfaceName := common.GetReference(handler)
@@ -116,7 +118,7 @@ func (s *Server) genSvcOpts(handler any, info 
*common.ServiceInfo, opts ...Servi
        newSvcOpts := defaultServiceOptions()
        if appCfg != nil {
                svcOpts = append(svcOpts,
-                       SetApplication(s.cfg.Application),
+                       SetApplication(appCfg),
                )
        }
        if proCfg != nil {
@@ -288,6 +290,9 @@ func enhanceServiceInfo(info *common.ServiceInfo) 
*common.ServiceInfo {
 }
 
 func (s *Server) exportServices() error {
+       // add read lock to protect svcOptsMap data
+       s.mu.RLock()
+       defer s.mu.RUnlock()
        for _, svcOpts := range s.svcOptsMap {
                if err := svcOpts.Export(); err != nil {
                        logger.Errorf("export %s service failed, err: %s", 
svcOpts.Service.Interface, err)
@@ -299,12 +304,17 @@ func (s *Server) exportServices() error {
 
 func (s *Server) Serve() error {
        s.mu.Lock()
-       defer s.mu.Unlock()
        if s.serve {
+               // release lock in case causing deadlock
+               s.mu.Unlock()
                return errors.New("server has already been started")
        }
        // prevent multiple calls to Serve
        s.serve = true
+
+       // release lock in case causing deadlock
+       s.mu.Unlock()
+
        // the registryConfig in ServiceOptions and ServerOptions all need to 
init a metadataReporter,
        // when ServiceOptions.init() is called we don't know if a new registry 
config is set in the future use serviceOption
        if err := metadata.InitRegistryMetadataReport(s.cfg.Registries); err != 
nil {
@@ -335,6 +345,7 @@ func (s *Server) Serve() error {
 // In order to expose internal services
 func (s *Server) exportInternalServices() error {
        cfg := &ServiceOptions{}
+
        cfg.Application = s.cfg.Application
        cfg.Provider = s.cfg.Provider
        cfg.Protocols = s.cfg.Protocols

Reply via email to