| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| package main |
|
|
| import ( |
| "io" |
| "os" |
| "runtime/pprof" |
| "time" |
| ) |
|
|
| func init() { |
| register("Grpc1275", Grpc1275) |
| } |
|
|
| type recvBuffer_grpc1275 struct { |
| c chan bool |
| } |
|
|
| func (b *recvBuffer_grpc1275) get() <-chan bool { |
| return b.c |
| } |
|
|
| type recvBufferReader_grpc1275 struct { |
| recv *recvBuffer_grpc1275 |
| } |
|
|
| func (r *recvBufferReader_grpc1275) Read(p []byte) (int, error) { |
| select { |
| case <-r.recv.get(): |
| } |
| return 0, nil |
| } |
|
|
| type Stream_grpc1275 struct { |
| trReader io.Reader |
| } |
|
|
| func (s *Stream_grpc1275) Read(p []byte) (int, error) { |
| return io.ReadFull(s.trReader, p) |
| } |
|
|
| type http2Client_grpc1275 struct{} |
|
|
| func (t *http2Client_grpc1275) CloseStream(s *Stream_grpc1275) { |
| |
| |
| |
| } |
|
|
| func (t *http2Client_grpc1275) NewStream() *Stream_grpc1275 { |
| return &Stream_grpc1275{ |
| trReader: &recvBufferReader_grpc1275{ |
| recv: &recvBuffer_grpc1275{ |
| c: make(chan bool), |
| }, |
| }, |
| } |
| } |
|
|
| func testInflightStreamClosing_grpc1275() { |
| client := &http2Client_grpc1275{} |
| stream := client.NewStream() |
| donec := make(chan bool) |
| go func() { |
| defer close(donec) |
| stream.Read([]byte{1}) |
| }() |
|
|
| client.CloseStream(stream) |
|
|
| timeout := time.NewTimer(300 * time.Nanosecond) |
| select { |
| case <-donec: |
| if !timeout.Stop() { |
| <-timeout.C |
| } |
| case <-timeout.C: |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| func Grpc1275() { |
| prof := pprof.Lookup("goroutineleak") |
| defer func() { |
| time.Sleep(100 * time.Millisecond) |
| prof.WriteTo(os.Stdout, 2) |
| }() |
| go func() { |
| testInflightStreamClosing_grpc1275() |
| }() |
| } |
|
|