You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by wi...@apache.org on 2026/10/02 02:40:38 UTC

(yunikorn-k8shim) branch master updated: [YUNIKORN-3424] createAppPlaceholders walks the application task map without the application lock (#1111)

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

wilfred-s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git


The following commit(s) were added to refs/heads/master by this push:
     new 41e452ac [YUNIKORN-3424] createAppPlaceholders walks the application task map without the application lock (#1111)
41e452ac is described below

commit 41e452acf81c6545dd8a5106a6d63840701a1a67
Author: HuangPinHan <hu...@gmail.com>
AuthorDate: Fri Oct 2 12:36:45 2026 +1000

    [YUNIKORN-3424] createAppPlaceholders walks the application task map without the application lock (#1111)
    
    Use the app locked version of getPlaceHolderTasks to check the already
    created placeholders in the PlaceholderManager
    No functional changes.
    
    Closes: #1111
    
    Signed-off-by: Wilfred Spiegelenburg <wi...@apache.org>
---
 pkg/cache/placeholder_manager.go      |  2 +-
 pkg/cache/placeholder_manager_test.go | 41 +++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/pkg/cache/placeholder_manager.go b/pkg/cache/placeholder_manager.go
index 17fc45e2..860ec575 100644
--- a/pkg/cache/placeholder_manager.go
+++ b/pkg/cache/placeholder_manager.go
@@ -75,7 +75,7 @@ func (mgr *PlaceholderManager) createAppPlaceholders(app *Application) error {
 
 	// map task group to count of already created placeholders
 	tgCounts := make(map[string]int32)
-	for _, ph := range app.getPlaceHolderTasks() {
+	for _, ph := range app.GetPlaceHolderTasks() {
 		tgCounts[ph.GetTaskGroupName()]++
 	}
 
diff --git a/pkg/cache/placeholder_manager_test.go b/pkg/cache/placeholder_manager_test.go
index 125a4f73..d62e02f8 100644
--- a/pkg/cache/placeholder_manager_test.go
+++ b/pkg/cache/placeholder_manager_test.go
@@ -21,6 +21,7 @@ package cache
 import (
 	"fmt"
 	"strings"
+	"sync"
 	"testing"
 	"time"
 
@@ -417,3 +418,43 @@ func TestPlaceholderManagerCleanup(t *testing.T) {
 	time.Sleep(5 * time.Millisecond)
 	assert.Equal(t, mgr.isRunning(), false, "placeholder manager has stopped")
 }
+
+// TestCreateAppPlaceholdersWithConcurrentTaskUpdates exercises createAppPlaceholders while
+// the informer path keeps adding tasks to the same application. createAppPlaceholders only
+// holds the placeholder manager lock, so the task map walk must take the application lock
+// itself. Run with -race: without that lock the walk races with addTask.
+func TestCreateAppPlaceholdersWithConcurrentTaskUpdates(t *testing.T) {
+	app := createAppWIthTaskGroupForTest()
+	mockedAPIProvider := client.NewMockedAPIProvider(false)
+	mgr := NewPlaceholderManager(mockedAPIProvider.GetAPIs())
+
+	readerDone := make(chan struct{})
+	var wg sync.WaitGroup
+	wg.Add(1)
+
+	// writer: simulates the informer adding pods to the application until the reader finishes
+	go func() {
+		defer wg.Done()
+		for i := 0; ; i++ {
+			select {
+			case <-readerDone:
+				return
+			default:
+			}
+			pod := &v1.Pod{
+				ObjectMeta: apis.ObjectMeta{
+					Name:      fmt.Sprintf("pod-%d", i),
+					Namespace: namespace,
+				},
+			}
+			app.addTask(NewTask(fmt.Sprintf("task-%d", i), app, nil, pod))
+		}
+	}()
+
+	// reader: the reserving path creating placeholders for the same application
+	for i := 0; i < 50; i++ {
+		assert.NilError(t, mgr.createAppPlaceholders(app))
+	}
+	close(readerDone)
+	wg.Wait()
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org