MCPcopy
hub / github.com/olric-data/olric / Shutdown

Method Shutdown

internal/discovery/discovery.go:280–318  ·  view source on GitHub ↗

Shutdown will stop any background maintenance of network activity for this memberlist, causing it to appear "dead". A leave message will not be broadcasted prior, so the cluster being left will have to detect this node's Shutdown using probing. If you wish to more gracefully exit the cluster, call L

()

Source from the content-addressed store, hash-verified

278//
279// This method is safe to call multiple times.
280func (d *Discovery) Shutdown() error {
281 select {
282 case <-d.ctx.Done():
283 return nil
284 default:
285 }
286 d.cancel()
287 // We don't do that in a goroutine with a timeout mechanism
288 // because this mechanism may cause goroutine leak.
289 d.wg.Wait()
290
291 if d.memberlist != nil {
292 // Leave will broadcast a leave message but will not shutdown the background
293 // listeners, meaning the node will continue participating in gossip and state
294 // updates.
295 d.log.V(2).Printf("[INFO] Broadcasting a leave message")
296 if err := d.memberlist.Leave(d.config.LeaveTimeout); err != nil {
297 d.log.V(3).Printf("[WARN] memberlist.Leave returned an error: %v", err)
298 }
299 }
300
301 if d.serviceDiscovery != nil {
302 defer func(serviceDiscovery service_discovery.ServiceDiscovery) {
303 err := serviceDiscovery.Close()
304 if err != nil {
305 d.log.V(3).Printf("[ERROR] ServiceDiscovery.Close returned an error: %v", err)
306 }
307 }(d.serviceDiscovery)
308
309 if err := d.serviceDiscovery.Deregister(); err != nil {
310 d.log.V(3).Printf("[ERROR] ServiceDiscovery.Deregister returned an error: %v", err)
311 }
312 }
313
314 if d.memberlist != nil {
315 return d.memberlist.Shutdown()
316 }
317 return nil
318}

Callers

nothing calls this directly

Calls 5

PrintfMethod · 0.80
VMethod · 0.80
CloseMethod · 0.65
DeregisterMethod · 0.65
ShutdownMethod · 0.65

Tested by

no test coverage detected