| 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/6632 |
| 8 |
* Buggy version: e597b41d939573502c8dda1dde7bf3439325fb5d |
| 9 |
* fix commit-id: 82afb7ab1fe12cf2efceede2322d082eaf5d5adc |
| 10 |
* Flaky: 4/100 |
| 11 |
*/ |
| 12 |
package main |
| 13 |
|
| 14 |
import ( |
| 15 |
"os" |
| 16 |
"runtime/pprof" |
| 17 |
"sync" |
| 18 |
"time" |
| 19 |
) |
| 20 |
|
| 21 |
func init() { |
| 22 |
register("Kubernetes6632", Kubernetes6632) |
| 23 |
} |
| 24 |
|
| 25 |
type Connection_kubernetes6632 struct { |
| 26 |
closeChan chan bool |
| 27 |
} |
| 28 |
|
| 29 |
type idleAwareFramer_kubernetes6632 struct { |
| 30 |
resetChan chan bool |
| 31 |
writeLock sync.Mutex |
| 32 |
conn *Connection_kubernetes6632 |
| 33 |
} |
| 34 |
|
| 35 |
func (i *idleAwareFramer_kubernetes6632) monitor() { |
| 36 |
var resetChan = i.resetChan |
| 37 |
Loop: |
| 38 |
for { |
| 39 |
select { |
| 40 |
case <-i.conn.closeChan: |
| 41 |
i.writeLock.Lock() |
| 42 |
close(resetChan) |
| 43 |
i.resetChan = nil |
| 44 |
i.writeLock.Unlock() |
| 45 |
break Loop |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func (i *idleAwareFramer_kubernetes6632) WriteFrame() { |
| 51 |
i.writeLock.Lock() |
| 52 |
defer i.writeLock.Unlock() |
| 53 |
if i.resetChan == nil { |
| 54 |
return |
| 55 |
} |
| 56 |
i.resetChan <- true |
| 57 |
} |
| 58 |
|
| 59 |
func NewIdleAwareFramer_kubernetes6632() *idleAwareFramer_kubernetes6632 { |
| 60 |
return &idleAwareFramer_kubernetes6632{ |
| 61 |
resetChan: make(chan bool), |
| 62 |
conn: &Connection_kubernetes6632{ |
| 63 |
closeChan: make(chan bool), |
| 64 |
}, |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
func Kubernetes6632() { |
| 69 |
prof := pprof.Lookup("goroutineleak") |
| 70 |
defer func() { |
| 71 |
time.Sleep(100 * time.Millisecond) |
| 72 |
prof.WriteTo(os.Stdout, 2) |
| 73 |
}() |
| 74 |
|
| 75 |
for i := 0; i < 100; i++ { |
| 76 |
go func() { |
| 77 |
i := NewIdleAwareFramer_kubernetes6632() |
| 78 |
|
| 79 |
go func() { // helper goroutine |
| 80 |
i.conn.closeChan <- true |
| 81 |
}() |
| 82 |
go i.monitor() // G1 |
| 83 |
go i.WriteFrame() // G2 |
| 84 |
}() |
| 85 |
} |
| 86 |
} |