-
Hi, I am playing around with https://pkg.go.dev/go.etcd.io/etcd/server/v3/embed. I am confused by the etcd.Close method and etcdserver.Stop method. When shutting down the program, in which order are they supposed to be called? i.e. like below, or the other way around? e, _ := embed.StartEtcd(cfg)
...
e.Server.Stop()
e.Close()
return <-e.Err() From the example here it seems like stop comes first, since the close call is deferred. https://github.com/etcd-io/etcd/blob/main/server/embed/doc.go#L27 But from my testing, e.Err may block until close is actually called. So deferring it may lead to the program hanging. For example see this https://go.dev/play/p/Trmcy9TV4ag. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you look at the code, the So it's enough to just Close. |
Beta Was this translation helpful? Give feedback.
-
I agree with @tjungblu . User application just needs to call Lines 185 to 199 in b27dec8 Also please feel free to raise a PR to fix the incorrect doc. |
Beta Was this translation helpful? Give feedback.
If you look at the code, the
Close
method will also stop:https://github.com/etcd-io/etcd/blob/server/v3.5.8/server/embed/etcd.go#L423-L426
So it's enough to just Close.