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 e97842cb9 [CELEBORN-2293] Fix ConcurrentModificationException in
WorkerStatusTracker.shuttingWorkers
e97842cb9 is described below
commit e97842cb9b3bcdc8c4a1e9e5fdb98b5434c27331
Author: Kartikay Bhutani <[email protected]>
AuthorDate: Thu Apr 2 10:50:09 2026 +0800
[CELEBORN-2293] Fix ConcurrentModificationException in
WorkerStatusTracker.shuttingWorkers
### What changes were proposed in this pull request?
Replace `HashSet` with `ConcurrentHashMap.newKeySet()` for
`shuttingWorkers` in `WorkerStatusTracker`.
### Why are the changes needed?
When multiple shuffles hit a shutting-down worker simultaneously, one
thread iterates `shuttingWorkers` in `currentFailedWorkers()` (for logging)
while another modifies it in `recordWorkerFailure()`.
### Does this PR resolve a correctness bug?
Yes.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Added a unit test in `WorkerStatusTrackerSuite` and ran the same. Was able
to reproduce only once (without the fix) out of multiple runs.
Closes #3638 from kaybhutani/fix-concurrent-shuttingworkers.
Lead-authored-by: Kartikay Bhutani <[email protected]>
Co-authored-by: kartikay <[email protected]>
Signed-off-by: SteNicholas <[email protected]>
(cherry picked from commit c3adbca3cd02f5f34ba120f86bffbee71fe78e03)
Signed-off-by: SteNicholas <[email protected]>
---
.../celeborn/client/WorkerStatusTracker.scala | 2 +-
.../celeborn/client/WorkerStatusTrackerSuite.scala | 67 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git
a/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
b/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
index 2e94e6cb4..2c1243acb 100644
--- a/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
+++ b/client/src/main/scala/org/apache/celeborn/client/WorkerStatusTracker.scala
@@ -39,7 +39,7 @@ class WorkerStatusTracker(
private val workerStatusListeners =
ConcurrentHashMap.newKeySet[WorkerStatusListener]()
val excludedWorkers = new ShuffleFailedWorkers()
- val shuttingWorkers: JSet[WorkerInfo] = new JHashSet[WorkerInfo]()
+ val shuttingWorkers: JSet[WorkerInfo] =
ConcurrentHashMap.newKeySet[WorkerInfo]()
def registerWorkerStatusListener(workerStatusListener:
WorkerStatusListener): Unit = {
workerStatusListeners.add(workerStatusListener)
diff --git
a/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
b/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
index 0355b4d86..90a1d53bb 100644
---
a/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
+++
b/client/src/test/scala/org/apache/celeborn/client/WorkerStatusTrackerSuite.scala
@@ -18,6 +18,11 @@
package org.apache.celeborn.client
import java.util
+import java.util.concurrent.{CyclicBarrier, Executors, Future, TimeUnit}
+import java.util.concurrent.atomic.AtomicInteger
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable.ArrayBuffer
import org.junit.Assert
@@ -92,6 +97,68 @@ class WorkerStatusTrackerSuite extends CelebornFunSuite {
Assert.assertFalse(statusTracker.excludedWorkers.containsKey(mock("host1")))
}
+ test("concurrent access to shuttingWorkers should not throw
ConcurrentModificationException") {
+ val celebornConf = new CelebornConf()
+ val statusTracker = new WorkerStatusTracker(celebornConf, null)
+ val numWriters = 5
+ val numReaders = 5
+ val totalThreads = numWriters + numReaders
+ val executor = Executors.newFixedThreadPool(totalThreads)
+ val barrier = new CyclicBarrier(totalThreads)
+ val errors = new AtomicInteger(0)
+ val futures = new ArrayBuffer[Future[_]]()
+
+ // Pre-populate the set so iteration takes longer, increasing the
+ // window for concurrent modification to trigger a CME with HashSet.
+ (1 to 1000).foreach { i =>
+ statusTracker.shuttingWorkers.add(mock(s"pre-$i"))
+ }
+
+ try {
+ // Writers: concurrently add and remove workers
+ (1 to numWriters).foreach { i =>
+ futures += executor.submit(new Runnable {
+ override def run(): Unit = {
+ barrier.await()
+ (1 to 1000).foreach { j =>
+ val worker = mock(s"host-$i-$j")
+ statusTracker.shuttingWorkers.add(worker)
+ statusTracker.shuttingWorkers.remove(worker)
+ }
+ }
+ })
+ }
+
+ // Readers: iterate shuttingWorkers directly, mirroring how
currentFailedWorkers iterates it
+ (1 to numReaders).foreach { i =>
+ futures += executor.submit(new Runnable {
+ override def run(): Unit = {
+ try {
+ barrier.await()
+ (1 to 1000).foreach { _ =>
+ statusTracker.shuttingWorkers.asScala.foreach(_ => ())
+ }
+ } catch {
+ case _: java.util.ConcurrentModificationException =>
+ errors.incrementAndGet()
+ }
+ }
+ })
+ }
+
+ // Surface any unexpected exceptions from threads
+ futures.foreach(_.get(30, TimeUnit.SECONDS))
+ } finally {
+ executor.shutdown()
+ Assert.assertTrue(executor.awaitTermination(30, TimeUnit.SECONDS))
+ }
+
+ Assert.assertEquals(
+ "ConcurrentModificationException should not occur with thread-safe set",
+ 0,
+ errors.get())
+ }
+
private def buildResponse(
excludedWorkerHosts: Array[String],
unknownWorkerHosts: Array[String],