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)
| 246 | // are any interesting (created by gRPC) goroutines leaked. It waits up to 10 |
| 247 | // seconds in the error cases. |
| 248 | func 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. |