Close gracefully shuts down all servers/listeners. Client requests will be terminated with request timeout. After timeout, enforce remaning requests be closed immediately. The rough workflow to shut down etcd: 1. close the `stopc` channel, so that all error handlers (child goroutines) won't send ba
()
| 416 | // safe to close the `errc` after step 7 above is done, otherwise the |
| 417 | // child goroutines may send errors back to already closed `errc` channel. |
| 418 | func (e *Etcd) Close() { |
| 419 | fields := []zap.Field{ |
| 420 | zap.String("name", e.cfg.Name), |
| 421 | zap.String("data-dir", e.cfg.Dir), |
| 422 | zap.Strings("advertise-peer-urls", e.cfg.getAdvertisePeerURLs()), |
| 423 | zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientURLs()), |
| 424 | } |
| 425 | lg := e.GetLogger() |
| 426 | lg.Info("closing etcd server", fields...) |
| 427 | defer func() { |
| 428 | lg.Info("closed etcd server", fields...) |
| 429 | verify.MustVerifyIfEnabled(verify.Config{ |
| 430 | Logger: lg, |
| 431 | DataDir: e.cfg.Dir, |
| 432 | ExactIndex: false, |
| 433 | }) |
| 434 | lg.Sync() |
| 435 | }() |
| 436 | |
| 437 | e.closeOnce.Do(func() { |
| 438 | close(e.stopc) |
| 439 | }) |
| 440 | |
| 441 | // close client requests with request timeout |
| 442 | timeout := 2 * time.Second |
| 443 | if e.Server != nil { |
| 444 | timeout = e.Server.Cfg.ReqTimeout() |
| 445 | } |
| 446 | for _, sctx := range e.sctxs { |
| 447 | for ss := range sctx.serversC { |
| 448 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 449 | stopServers(ctx, ss) |
| 450 | cancel() |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | for _, sctx := range e.sctxs { |
| 455 | sctx.cancel() |
| 456 | } |
| 457 | |
| 458 | for i := range e.Clients { |
| 459 | if e.Clients[i] != nil { |
| 460 | e.Clients[i].Close() |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | for i := range e.metricsListeners { |
| 465 | e.metricsListeners[i].Close() |
| 466 | } |
| 467 | |
| 468 | // shutdown tracing exporter |
| 469 | if e.tracingExporterShutdown != nil { |
| 470 | e.tracingExporterShutdown() |
| 471 | } |
| 472 | |
| 473 | // close rafthttp transports |
| 474 | if e.Server != nil { |
| 475 | e.Server.Stop() |
nothing calls this directly
no test coverage detected