@@ -121,7 +121,7 @@ func (w *WatchCache_kubernetes13135) Replace(obj interface{}) {
121
121
}
122
122
}
123
123
124
- func NewCacher_kubernetes13135 () * Cacher_kubernetes13135 {
124
+ func NewCacher_kubernetes13135 (stopCh <- chan struct {} ) * Cacher_kubernetes13135 {
125
125
watchCache := & WatchCache_kubernetes13135 {}
126
126
cacher := & Cacher_kubernetes13135 {
127
127
initialized : sync.WaitGroup {},
@@ -134,7 +134,6 @@ func NewCacher_kubernetes13135() *Cacher_kubernetes13135 {
134
134
cacher .Unlock ()
135
135
})
136
136
watchCache .SetOnEvent (cacher .processEvent )
137
- stopCh := StopChannel_kubernetes13135
138
137
go Util_kubernetes13135 (func () { cacher .startCaching (stopCh ) }, 0 , stopCh ) // G2
139
138
cacher .initialized .Wait ()
140
139
return cacher
@@ -166,6 +165,19 @@ func NewCacher_kubernetes13135() *Cacher_kubernetes13135 {
166
165
///--------------------------------G2,G3 deadlock-------------------------------------
167
166
///
168
167
168
+ ///
169
+ /// G1 G2 G3
170
+ /// NewCacher()
171
+ /// watchCache.SetOnReplace()
172
+ /// watchCache.SetOnEvent()
173
+ /// watchCache.initialized.Wait()
174
+ /// Util(...)
175
+ ///
176
+ /// cacher.startCaching()
177
+ /// c.Lock()
178
+ /// c.reflector.ListAndWatch()
179
+ /// r.syncWith()
180
+ ///--------------------------------G1 deadlocks-------------------------------------
169
181
func Kubernetes13135 () {
170
182
prof := pprof .Lookup ("goroutineleak" )
171
183
defer func () {
@@ -176,10 +188,15 @@ func Kubernetes13135() {
176
188
StopChannel_kubernetes13135 = make (chan struct {})
177
189
for i := 0 ; i < 50 ; i ++ {
178
190
go func () {
191
+ // Should create a local channel. Using a single global channel
192
+ // concurrently will cause a deadlock which does not actually exist
193
+ // in the original microbenchmark.
194
+ StopChannel_kubernetes13135 := make (chan struct {})
195
+
179
196
// deadlocks: x > 0
180
- c := NewCacher_kubernetes13135 () // G1
197
+ c := NewCacher_kubernetes13135 (StopChannel_kubernetes13135 ) // G1
181
198
go c .watchCache .Add (nil ) // G3
199
+ go close (StopChannel_kubernetes13135 )
182
200
}()
183
201
}
184
- go close (StopChannel_kubernetes13135 )
185
202
}
0 commit comments