You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by ma...@apache.org on 2026/09/30 07:46:02 UTC

(yunikorn-k8shim) branch master updated: [YUNIKORN-3425] Fix data race on admission controller server field (#1110)

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

manirajv06 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 01485eb6 [YUNIKORN-3425] Fix data race on admission controller server field (#1110)
01485eb6 is described below

commit 01485eb66667c4bbd65e62b4539a94dda1afbccb
Author: PoiBlackTea <ki...@gmail.com>
AuthorDate: Wed Sep 30 13:15:47 2026 +0530

    [YUNIKORN-3425] Fix data race on admission controller server field (#1110)
    
    Closes: #1110
    
    Signed-off-by: Manikandan R <ma...@gmail.com>
---
 pkg/cmd/admissioncontroller/main.go      | 14 +++++++------
 pkg/cmd/admissioncontroller/main_test.go | 36 ++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/pkg/cmd/admissioncontroller/main.go b/pkg/cmd/admissioncontroller/main.go
index db1aa306..fe8b0f3b 100644
--- a/pkg/cmd/admissioncontroller/main.go
+++ b/pkg/cmd/admissioncontroller/main.go
@@ -153,7 +153,7 @@ func (wh *WebHook) Startup(certs *tls.Certificate) {
 	mux.HandleFunc(mutateURL, wh.ac.Serve)
 	mux.HandleFunc(validateConfURL, wh.ac.Serve)
 
-	wh.server = &http.Server{
+	server := &http.Server{
 		Addr: fmt.Sprintf(":%v", wh.port),
 		TLSConfig: &tls.Config{
 			MinVersion:   tls.VersionTLS12,           // No SSL, TLS 1.0 or TLS 1.1 support
@@ -164,9 +164,10 @@ func (wh *WebHook) Startup(certs *tls.Certificate) {
 		Handler:           mux,
 		ReadHeaderTimeout: 10 * time.Second,
 	}
+	wh.server = server
 
 	go func() {
-		if err := wh.server.ListenAndServeTLS("", ""); err != nil {
+		if err := server.ListenAndServeTLS("", ""); err != nil {
 			if errors.Is(err, http.ErrServerClosed) {
 				log.Log(log.Admission).Info("existing server closed")
 			} else {
@@ -182,15 +183,16 @@ func (wh *WebHook) Startup(certs *tls.Certificate) {
 
 func (wh *WebHook) Shutdown() {
 	wh.Lock()
-	defer wh.Unlock()
+	server := wh.server
+	wh.server = nil
+	wh.Unlock()
 
-	if wh.server != nil {
+	if server != nil {
 		log.Log(log.Admission).Info("shutting down the admission controller...")
-		err := wh.server.Shutdown(context.Background())
+		err := server.Shutdown(context.Background())
 		if err != nil {
 			log.Log(log.Admission).Fatal("failed to stop the admission controller", zap.Error(err))
 		}
-		wh.server = nil
 	}
 }
 
diff --git a/pkg/cmd/admissioncontroller/main_test.go b/pkg/cmd/admissioncontroller/main_test.go
new file mode 100644
index 00000000..8a0c89ef
--- /dev/null
+++ b/pkg/cmd/admissioncontroller/main_test.go
@@ -0,0 +1,36 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package main
+
+import (
+	"crypto/tls"
+	"testing"
+
+	"gotest.tools/v3/assert"
+)
+
+func TestWebhookStartupShutdownRace(t *testing.T) {
+	webhook := CreateWebhook(nil, 0)
+	for i := 0; i < 100; i++ {
+		webhook.Startup(&tls.Certificate{})
+		assert.Assert(t, webhook.server != nil, "startup must set the server")
+		webhook.Shutdown()
+		assert.Assert(t, webhook.server == nil, "shutdown must clear the server")
+	}
+}


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