Shutdown is called when memberlist is shutting down; this gives the transport a chance to clean up any listeners. This will avoid log spam about errors when we shut down.
()
| 625 | // transport a chance to clean up any listeners. |
| 626 | // This will avoid log spam about errors when we shut down. |
| 627 | func (t *TCPTransport) Shutdown() error { |
| 628 | t.shutdownMu.Lock() |
| 629 | // This will avoid log spam about errors when we shut down. |
| 630 | if t.shutdown { |
| 631 | t.shutdownMu.Unlock() |
| 632 | return nil // already shut down |
| 633 | } |
| 634 | |
| 635 | // Set the shutdown flag and close the write channel. |
| 636 | t.shutdown = true |
| 637 | close(t.writeCh) |
| 638 | t.shutdownMu.Unlock() |
| 639 | |
| 640 | // Rip through all the connections and shut them down. |
| 641 | for _, conn := range t.tcpListeners { |
| 642 | _ = conn.Close() |
| 643 | } |
| 644 | |
| 645 | // Wait until all write workers have finished. |
| 646 | t.writeWG.Wait() |
| 647 | |
| 648 | // Block until all the listener threads have died. |
| 649 | t.wg.Wait() |
| 650 | |
| 651 | return nil |
| 652 | } |
| 653 | |
| 654 | func (t *TCPTransport) registerMetrics(registerer prometheus.Registerer) { |
| 655 | const subsystem = "memberlist_tcp_transport" |