xh1202 opened a new issue, #10249:
URL: https://github.com/apache/dubbo/issues/10249

   
问题描述:线程1和线程2同时执行的情况下,线程1获取锁并创建registry实例然后释放锁,接着线程2获取锁并创建registry实例,最后线程1、2先后将registry存入registryManager中,导致重复创建registry对象
   
   ```
           registryManager.getRegistryLock().lock();
           try {
               // double check
               // fix https://github.com/apache/dubbo/issues/7265.
               defaultNopRegistry = 
registryManager.getDefaultNopRegistryIfDestroyed();
               if (null != defaultNopRegistry) {
                   return defaultNopRegistry;
               }
               registry = registryManager.getRegistry(key);
               if (registry != null) {
                   return registry;
               }
               //create registry by spi/ioc
               registry = createRegistry(url);
           } catch (Exception e) {
               if (check) {
                   throw new RuntimeException("Can not create registry " + url, 
e);
               } else {
                   LOGGER.warn("Failed to obtain or create registry ", e);
               }
           } finally {
               // Release the lock
               registryManager.getRegistryLock().unlock();
           }
   
           if (check && registry == null) {
               throw new IllegalStateException("Can not create registry " + 
url);
           }
   
           if (registry != null) {
               registryManager.putRegistry(key, registry);
           }
   ```
   
   解决方法:执行registryManager.putRegistry(key, registry)之后再释放锁
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to