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

nicholasjiang pushed a commit to branch branch-0.6
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/branch-0.6 by this push:
     new ee667838b [CELEBORN-2296] Fix race condition in MemoryManager 
singleton initialization
ee667838b is described below

commit ee667838b51f914c8fa12e805b65a7b0c6c0fc6b
Author: sychen <[email protected]>
AuthorDate: Thu Apr 2 10:56:26 2026 +0800

    [CELEBORN-2296] Fix race condition in MemoryManager singleton initialization
    
    ### What changes were proposed in this pull request?
    Apply double-checked locking to MemoryManager.initialize() and add 
synchronized to MemoryManager.reset() to make the singleton lifecycle 
thread-safe.
    
    ### Why are the changes needed?
    
    ```java
    26/04/01 10:32:20,050 ERROR [worker 3 starter thread] 
WordCountTestWithAuthentication: create worker failed, detail:
    java.lang.NullPointerException
            at 
org.apache.celeborn.service.deploy.worker.memory.ChannelsLimiter.<init>(ChannelsLimiter.java:52)
            at 
org.apache.celeborn.service.deploy.worker.Worker.<init>(Worker.scala:240)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature.createWorker(MiniClusterFeature.scala:172)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature.createWorker$(MiniClusterFeature.scala:153)
            at 
org.apache.celeborn.tests.flink.WordCountTestBase.createWorker(WordCountTest.scala:44)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature.createWorker(MiniClusterFeature.scala:150)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature.createWorker$(MiniClusterFeature.scala:149)
            at 
org.apache.celeborn.tests.flink.WordCountTestBase.createWorker(WordCountTest.scala:44)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature.$anonfun$setUpWorkers$2(MiniClusterFeature.scala:221)
            at 
scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature$RunnerWrap.$anonfun$run$1(MiniClusterFeature.scala:50)
            at 
org.apache.celeborn.common.util.Utils$.tryLogNonFatalError(Utils.scala:234)
            at 
org.apache.celeborn.service.deploy.MiniClusterFeature$RunnerWrap.run(MiniClusterFeature.scala:50)
    ```
    
    ### Does this PR resolve a correctness bug?
    No
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    GHA
    
    Closes #3643 from cxzl25/CELEBORN-2296.
    
    Authored-by: sychen <[email protected]>
    Signed-off-by: SteNicholas <[email protected]>
    (cherry picked from commit 37a27bc4cb3c993289e5b94439db224572cd3e66)
    Signed-off-by: SteNicholas <[email protected]>
---
 .../celeborn/service/deploy/worker/memory/MemoryManager.java      | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
 
b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
index 76898bd3d..887c001e1 100644
--- 
a/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
+++ 
b/worker/src/main/java/org/apache/celeborn/service/deploy/worker/memory/MemoryManager.java
@@ -109,7 +109,11 @@ public class MemoryManager {
   public static MemoryManager initialize(
       CelebornConf conf, StorageManager storageManager, AbstractSource source) 
{
     if (_INSTANCE == null) {
-      _INSTANCE = new MemoryManager(conf, storageManager, source);
+      synchronized (MemoryManager.class) {
+        if (_INSTANCE == null) {
+          _INSTANCE = new MemoryManager(conf, storageManager, source);
+        }
+      }
     }
     return _INSTANCE;
   }
@@ -590,7 +594,7 @@ public class MemoryManager {
   }
 
   @VisibleForTesting
-  public static void reset() {
+  public static synchronized void reset() {
     _INSTANCE = null;
   }
 

Reply via email to