shutdownWorkers gracefully shuts down the worker manager, waiting for workers to complete
(ctx context.Context)
| 328 | |
| 329 | // shutdownWorkers gracefully shuts down the worker manager, waiting for workers to complete |
| 330 | func (hwm *handoffWorkerManager) shutdownWorkers(ctx context.Context) error { |
| 331 | hwm.shutdownOnce.Do(func() { |
| 332 | close(hwm.shutdown) |
| 333 | // workers will exit when they finish their current request |
| 334 | |
| 335 | // Shutdown circuit breaker manager cleanup goroutine |
| 336 | if hwm.circuitBreakerManager != nil { |
| 337 | hwm.circuitBreakerManager.Shutdown() |
| 338 | } |
| 339 | }) |
| 340 | |
| 341 | // Wait for workers to complete |
| 342 | done := make(chan struct{}) |
| 343 | go func() { |
| 344 | hwm.workerWg.Wait() |
| 345 | close(done) |
| 346 | }() |
| 347 | |
| 348 | select { |
| 349 | case <-done: |
| 350 | return nil |
| 351 | case <-ctx.Done(): |
| 352 | return ctx.Err() |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | // performConnectionHandoff performs the actual connection handoff |
| 357 | // When error is returned, the connection handoff should be retried if err is not ErrMaxHandoffRetriesReached |