| 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: grpc-go |
| 7 |
* Issue or PR : https://github.com/grpc/grpc-go/pull/660 |
| 8 |
* Buggy version: db85417dd0de6cc6f583672c6175a7237e5b5dd2 |
| 9 |
* fix commit-id: ceacfbcbc1514e4e677932fd55938ac455d182fb |
| 10 |
* Flaky: 100/100 |
| 11 |
*/ |
| 12 |
package main |
| 13 |
|
| 14 |
import ( |
| 15 |
"math/rand" |
| 16 |
"os" |
| 17 |
"runtime" |
| 18 |
"runtime/pprof" |
| 19 |
) |
| 20 |
|
| 21 |
func init() { |
| 22 |
register("Grpc660", Grpc660) |
| 23 |
} |
| 24 |
|
| 25 |
type benchmarkClient_grpc660 struct { |
| 26 |
stop chan bool |
| 27 |
} |
| 28 |
|
| 29 |
func (bc *benchmarkClient_grpc660) doCloseLoopUnary() { |
| 30 |
for { |
| 31 |
done := make(chan bool) |
| 32 |
go func() { // G2 |
| 33 |
if rand.Intn(10) > 7 { |
| 34 |
done <- false |
| 35 |
return |
| 36 |
} |
| 37 |
done <- true |
| 38 |
}() |
| 39 |
select { |
| 40 |
case <-bc.stop: |
| 41 |
return |
| 42 |
case <-done: |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
func Grpc660() { |
| 48 |
prof := pprof.Lookup("goroutineleak") |
| 49 |
defer func() { |
| 50 |
// Yield several times to allow the child goroutine to run. |
| 51 |
for i := 0; i < yieldCount; i++ { |
| 52 |
runtime.Gosched() |
| 53 |
} |
| 54 |
prof.WriteTo(os.Stdout, 2) |
| 55 |
}() |
| 56 |
go func() { |
| 57 |
bc := &benchmarkClient_grpc660{ |
| 58 |
stop: make(chan bool), |
| 59 |
} |
| 60 |
go bc.doCloseLoopUnary() // G1 |
| 61 |
go func() { // helper goroutine |
| 62 |
bc.stop <- true |
| 63 |
}() |
| 64 |
}() |
| 65 |
} |