1
2
3
4
5
12
13 package main
14
15 import (
16 "errors"
17 "math/rand"
18 "os"
19 "runtime"
20 "runtime/pprof"
21 "time"
22 )
23
24 func init() {
25 register("Kubernetes5316", Kubernetes5316)
26 }
27
28 func finishRequest_kubernetes5316(timeout time.Duration, fn func() error) {
29 ch := make(chan bool)
30 errCh := make(chan error)
31 go func() {
32 if err := fn(); err != nil {
33 errCh <- err
34 } else {
35 ch <- true
36 }
37 }()
38
39 select {
40 case <-ch:
41 case <-errCh:
42 case <-time.After(timeout):
43 }
44 }
45
46 func Kubernetes5316() {
47 prof := pprof.Lookup("goroutineleak")
48 defer func() {
49
50 time.Sleep(100 * time.Millisecond)
51
52
53 for i := 0; i < yieldCount; i++ {
54 runtime.Gosched()
55 }
56 prof.WriteTo(os.Stdout, 2)
57 }()
58 go func() {
59 fn := func() error {
60 time.Sleep(2 * time.Millisecond)
61 if rand.Intn(10) > 5 {
62 return errors.New("Error")
63 }
64 return nil
65 }
66 go finishRequest_kubernetes5316(time.Microsecond, fn)
67 }()
68 }
69
View as plain text