| 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 |
package main |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
"runtime/pprof" |
| 10 |
"sync" |
| 11 |
"time" |
| 12 |
) |
| 13 |
|
| 14 |
func init() { |
| 15 |
register("Grpc795", Grpc795) |
| 16 |
} |
| 17 |
|
| 18 |
type Server_grpc795 struct { |
| 19 |
mu sync.Mutex |
| 20 |
drain bool |
| 21 |
} |
| 22 |
|
| 23 |
func (s *Server_grpc795) GracefulStop() { |
| 24 |
s.mu.Lock() |
| 25 |
if s.drain { |
| 26 |
s.mu.Lock() |
| 27 |
return |
| 28 |
} |
| 29 |
s.drain = true |
| 30 |
s.mu.Unlock() |
| 31 |
} |
| 32 |
func (s *Server_grpc795) Serve() { |
| 33 |
s.mu.Lock() |
| 34 |
s.mu.Unlock() |
| 35 |
} |
| 36 |
|
| 37 |
func NewServer_grpc795() *Server_grpc795 { |
| 38 |
return &Server_grpc795{} |
| 39 |
} |
| 40 |
|
| 41 |
type test_grpc795 struct { |
| 42 |
srv *Server_grpc795 |
| 43 |
} |
| 44 |
|
| 45 |
func (te *test_grpc795) startServer() { |
| 46 |
s := NewServer_grpc795() |
| 47 |
te.srv = s |
| 48 |
go s.Serve() |
| 49 |
} |
| 50 |
|
| 51 |
func newTest_grpc795() *test_grpc795 { |
| 52 |
return &test_grpc795{} |
| 53 |
} |
| 54 |
|
| 55 |
func testServerGracefulStopIdempotent_grpc795() { |
| 56 |
te := newTest_grpc795() |
| 57 |
|
| 58 |
te.startServer() |
| 59 |
|
| 60 |
for i := 0; i < 3; i++ { |
| 61 |
te.srv.GracefulStop() |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
func Grpc795() { |
| 66 |
prof := pprof.Lookup("goroutineleak") |
| 67 |
defer func() { |
| 68 |
time.Sleep(100 * time.Millisecond) |
| 69 |
prof.WriteTo(os.Stdout, 2) |
| 70 |
}() |
| 71 |
for i := 0; i < 100; i++ { |
| 72 |
go testServerGracefulStopIdempotent_grpc795() |
| 73 |
} |
| 74 |
} |