From ab29dff1642120d30cc2260b5e2156c9837bf358 Mon Sep 17 00:00:00 2001 From: itayherzberg Date: Wed, 21 Oct 2026 19:17:58 +0300 Subject: [PATCH] fix(server): Worker.Stop blocked forever, so shutdown waited for SIGKILL Worker.Start adds to the worker's WaitGroup and Worker.Stop waits on it, but the work loop never called Done. TaskManager.Stop therefore blocked on the first worker, Server.Shutdown never got past it, and the process ignored SIGTERM until the kubelet killed it at the end of the 30-second grace period. kubevirtClient.Close, which stops the watchers, never ran. Every rollout took 30s longer than it needed to. Release the WaitGroup when the work loop exits. Signed-off-by: itayherzberg --- pkg/server/task_manager.go | 1 + pkg/server/worker_test.go | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 pkg/server/worker_test.go diff --git a/pkg/server/task_manager.go b/pkg/server/task_manager.go index 026248c..5c2df15 100644 --- a/pkg/server/task_manager.go +++ b/pkg/server/task_manager.go @@ -192,6 +192,7 @@ func (w *Worker) Stop() { // work is the main work loop for a worker func (w *Worker) work() { + defer w.wg.Done() logger.Debug("Worker %d starting work loop", w.ID) for { select { diff --git a/pkg/server/worker_test.go b/pkg/server/worker_test.go new file mode 100644 index 0000000..c819f44 --- /dev/null +++ b/pkg/server/worker_test.go @@ -0,0 +1,44 @@ +/* + * This file is part of the KubeVirt Redfish project + * + * Licensed 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. + * + * Copyright 2025 KubeVirt Redfish project and its authors. + * + */ + +package server + +import ( + "testing" + "time" +) + +// Stopping a worker must return once its work loop has exited. Server +// shutdown waits on this, so a Stop that never returns keeps the process +// alive until the kubelet kills it. +func TestWorkerStopReturns(t *testing.T) { + tm := NewTaskManager(1, nil) + + stopped := make(chan struct{}) + go func() { + tm.Stop() + close(stopped) + }() + + select { + case <-stopped: + case <-time.After(5 * time.Second): + t.Fatal("TaskManager.Stop did not return within 5s: Worker.Stop waits on a WaitGroup that the work loop never releases") + } +}