@@ -411,19 +411,6 @@ func (e *Etcd) Close() {
411411 close (e .stopc )
412412 })
413413
414- // close client requests with request timeout
415- timeout := 2 * time .Second
416- if e .Server != nil {
417- timeout = e .Server .Cfg .ReqTimeout ()
418- }
419- for _ , sctx := range e .sctxs {
420- for ss := range sctx .serversC {
421- ctx , cancel := context .WithTimeout (context .Background (), timeout )
422- stopServers (ctx , ss )
423- cancel ()
424- }
425- }
426-
427414 for _ , sctx := range e .sctxs {
428415 sctx .cancel ()
429416 }
@@ -443,11 +430,6 @@ func (e *Etcd) Close() {
443430 e .tracingExporterShutdown ()
444431 }
445432
446- // close rafthttp transports
447- if e .Server != nil {
448- e .Server .Stop ()
449- }
450-
451433 // close all idle connections in peer handler (wait up to 1-second)
452434 for i := range e .Peers {
453435 if e .Peers [i ] != nil && e .Peers [i ].close != nil {
@@ -456,6 +438,25 @@ func (e *Etcd) Close() {
456438 cancel ()
457439 }
458440 }
441+
442+ // close client requests with request timeout
443+ timeout := 2 * time .Second
444+ if e .Server != nil {
445+ timeout = e .Server .Cfg .ReqTimeout ()
446+ }
447+ for _ , sctx := range e .sctxs {
448+ for ss := range sctx .serversC {
449+ ctx , cancel := context .WithTimeout (context .Background (), timeout )
450+ stopServers (ctx , ss )
451+ cancel ()
452+ }
453+ }
454+
455+ // close rafthttp transports
456+ if e .Server != nil {
457+ e .Server .Stop ()
458+ }
459+
459460 if e .errc != nil {
460461 e .wg .Wait ()
461462 close (e .errc )
0 commit comments