mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 13:57:38 +00:00
Fix goroutine leak in pluginmanager test
Use a buffered channel for the operation start signal to prevent goroutines from blocking indefinitely. When the test receiver times out before all goroutines send their signal, an unbuffered channel causes those goroutines to block forever on the send operation. The buffer size is computed dynamically using max() to ensure it always accommodates the maximum number of concurrent operations any test may spawn.
This commit is contained in:
@@ -34,6 +34,10 @@ import (
|
||||
const (
|
||||
numPluginsToRegister = 2
|
||||
numPluginsToUnregister = 2
|
||||
// maxConcurrentOperations is the buffer size for the ch channel.
|
||||
// Must be >= max number of goroutines any test spawns to prevent
|
||||
// goroutine leaks when timeout fires before all sends complete.
|
||||
maxConcurrentOperations = max(numPluginsToRegister, numPluginsToUnregister)
|
||||
)
|
||||
|
||||
var _ OperationGenerator = &fakeOperationGenerator{}
|
||||
@@ -178,7 +182,7 @@ loop:
|
||||
|
||||
func setup(t *testing.T) (context.Context, chan interface{}, chan interface{}, OperationExecutor) {
|
||||
tCtx := ktesting.Init(t)
|
||||
ch, quit := make(chan interface{}), make(chan interface{})
|
||||
ch, quit := make(chan interface{}, maxConcurrentOperations), make(chan interface{})
|
||||
return tCtx, ch, quit, NewOperationExecutor(newFakeOperationGenerator(ch, quit))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user