| 1 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a MIT |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
/* |
| 6 |
* Project: kubernetes |
| 7 |
* Issue or PR : https://github.com/kubernetes/kubernetes/pull/62464 |
| 8 |
* Buggy version: a048ca888ad27367b1a7b7377c67658920adbf5d |
| 9 |
* fix commit-id: c1b19fce903675b82e9fdd1befcc5f5d658bfe78 |
| 10 |
* Flaky: 8/100 |
| 11 |
*/ |
| 12 |
|
| 13 |
package main |
| 14 |
|
| 15 |
import ( |
| 16 |
"math/rand" |
| 17 |
"os" |
| 18 |
"runtime" |
| 19 |
"runtime/pprof" |
| 20 |
"sync" |
| 21 |
"time" |
| 22 |
) |
| 23 |
|
| 24 |
func init() { |
| 25 |
register("Kubernetes62464", Kubernetes62464) |
| 26 |
} |
| 27 |
|
| 28 |
type State_kubernetes62464 interface { |
| 29 |
GetCPUSetOrDefault() |
| 30 |
GetCPUSet() bool |
| 31 |
GetDefaultCPUSet() |
| 32 |
SetDefaultCPUSet() |
| 33 |
} |
| 34 |
|
| 35 |
type stateMemory_kubernetes62464 struct { |
| 36 |
sync.RWMutex |
| 37 |
} |
| 38 |
|
| 39 |
func (s *stateMemory_kubernetes62464) GetCPUSetOrDefault() { |
| 40 |
s.RLock() |
| 41 |
defer s.RUnlock() |
| 42 |
if ok := s.GetCPUSet(); ok { |
| 43 |
return |
| 44 |
} |
| 45 |
s.GetDefaultCPUSet() |
| 46 |
} |
| 47 |
|
| 48 |
func (s *stateMemory_kubernetes62464) GetCPUSet() bool { |
| 49 |
runtime.Gosched() |
| 50 |
s.RLock() |
| 51 |
defer s.RUnlock() |
| 52 |
|
| 53 |
if rand.Intn(10) > 5 { |
| 54 |
return true |
| 55 |
} |
| 56 |
return false |
| 57 |
} |
| 58 |
|
| 59 |
func (s *stateMemory_kubernetes62464) GetDefaultCPUSet() { |
| 60 |
s.RLock() |
| 61 |
defer s.RUnlock() |
| 62 |
} |
| 63 |
|
| 64 |
func (s *stateMemory_kubernetes62464) SetDefaultCPUSet() { |
| 65 |
s.Lock() |
| 66 |
runtime.Gosched() |
| 67 |
defer s.Unlock() |
| 68 |
} |
| 69 |
|
| 70 |
type staticPolicy_kubernetes62464 struct{} |
| 71 |
|
| 72 |
func (p *staticPolicy_kubernetes62464) RemoveContainer(s State_kubernetes62464) { |
| 73 |
s.GetDefaultCPUSet() |
| 74 |
s.SetDefaultCPUSet() |
| 75 |
} |
| 76 |
|
| 77 |
type manager_kubernetes62464 struct { |
| 78 |
state *stateMemory_kubernetes62464 |
| 79 |
} |
| 80 |
|
| 81 |
func (m *manager_kubernetes62464) reconcileState() { |
| 82 |
m.state.GetCPUSetOrDefault() |
| 83 |
} |
| 84 |
|
| 85 |
func NewPolicyAndManager_kubernetes62464() (*staticPolicy_kubernetes62464, *manager_kubernetes62464) { |
| 86 |
s := &stateMemory_kubernetes62464{} |
| 87 |
m := &manager_kubernetes62464{s} |
| 88 |
p := &staticPolicy_kubernetes62464{} |
| 89 |
return p, m |
| 90 |
} |
| 91 |
|
| 92 |
/// |
| 93 |
/// G1 G2 |
| 94 |
/// m.reconcileState() |
| 95 |
/// m.state.GetCPUSetOrDefault() |
| 96 |
/// s.RLock() |
| 97 |
/// s.GetCPUSet() |
| 98 |
/// p.RemoveContainer() |
| 99 |
/// s.GetDefaultCPUSet() |
| 100 |
/// s.SetDefaultCPUSet() |
| 101 |
/// s.Lock() |
| 102 |
/// s.RLock() |
| 103 |
/// ---------------------G1,G2 deadlock--------------------- |
| 104 |
/// |
| 105 |
|
| 106 |
func Kubernetes62464() { |
| 107 |
prof := pprof.Lookup("goroutineleak") |
| 108 |
defer func() { |
| 109 |
time.Sleep(100 * time.Millisecond) |
| 110 |
prof.WriteTo(os.Stdout, 2) |
| 111 |
}() |
| 112 |
|
| 113 |
for i := 0; i < 1000; i++ { |
| 114 |
go func() { |
| 115 |
p, m := NewPolicyAndManager_kubernetes62464() |
| 116 |
go m.reconcileState() |
| 117 |
go p.RemoveContainer(m.state) |
| 118 |
}() |
| 119 |
} |
| 120 |
} |