1
2
3
4
5
12
13 package main
14
15 import (
16 "context"
17 "os"
18 "runtime/pprof"
19 "time"
20 )
21
22 func init() {
23 register("Moby33781", Moby33781)
24 }
25
26 func monitor_moby33781(stop chan bool) {
27 probeInterval := time.Millisecond
28 probeTimeout := time.Millisecond
29 for {
30 select {
31 case <-stop:
32 return
33 case <-time.After(probeInterval):
34 results := make(chan bool)
35 ctx, cancelProbe := context.WithTimeout(context.Background(), probeTimeout)
36 go func() {
37 results <- true
38 close(results)
39 }()
40 select {
41 case <-stop:
42
43 cancelProbe()
44 return
45 case <-results:
46 cancelProbe()
47 case <-ctx.Done():
48 cancelProbe()
49 <-results
50 }
51 }
52 }
53 }
54
55 func Moby33781() {
56 prof := pprof.Lookup("goroutineleak")
57 defer func() {
58 time.Sleep(100 * time.Millisecond)
59 prof.WriteTo(os.Stdout, 2)
60 }()
61 for i := 0; i < 100; i++ {
62 go func(i int) {
63 stop := make(chan bool)
64 go monitor_moby33781(stop)
65 go func() {
66 time.Sleep(time.Duration(i) * time.Millisecond)
67 stop <- true
68 }()
69 }(i)
70 }
71 }
72
View as plain text