MCPcopy
hub / github.com/grpc/grpc-go / CheckGoroutines

Function CheckGoroutines

internal/leakcheck/leakcheck.go:248–261  ·  view source on GitHub ↗

CheckGoroutines looks at the currently-running goroutines and checks if there are any interesting (created by gRPC) goroutines leaked. It waits up to 10 seconds in the error cases.

(ctx context.Context, logger Logger)

Source from the content-addressed store, hash-verified

246// are any interesting (created by gRPC) goroutines leaked. It waits up to 10
247// seconds in the error cases.
248func CheckGoroutines(ctx context.Context, logger Logger) {
249 // Loop, waiting for goroutines to shut down.
250 // Wait up to timeout, but finish as quickly as possible.
251 var leaked []string
252 for ctx.Err() == nil {
253 if leaked = interestingGoroutines(); len(leaked) == 0 {
254 return
255 }
256 time.Sleep(50 * time.Millisecond)
257 }
258 for _, g := range leaked {
259 logger.Errorf("Leaked goroutine: %v", g)
260 }
261}
262
263// LeakChecker captures a Logger and is returned by NewLeakChecker as a
264// convenient method to set up leak check tests in a unit test.

Callers 4

TestGracefulCloseMethod · 0.92
TeardownMethod · 0.92
TestCheckFunction · 0.85
TestCheckRegisterIgnoreFunction · 0.85

Calls 3

interestingGoroutinesFunction · 0.85
ErrMethod · 0.80
ErrorfMethod · 0.65

Tested by 3

TestGracefulCloseMethod · 0.74
TestCheckFunction · 0.68
TestCheckRegisterIgnoreFunction · 0.68