Close shuts down the Wireguard connection.
()
| 665 | |
| 666 | // Close shuts down the Wireguard connection. |
| 667 | func (c *Conn) Close() error { |
| 668 | c.logger.Info(context.Background(), "closing tailnet Conn") |
| 669 | c.watchCancel() |
| 670 | c.configMaps.close() |
| 671 | c.nodeUpdater.close() |
| 672 | c.mutex.Lock() |
| 673 | select { |
| 674 | case <-c.closed: |
| 675 | c.mutex.Unlock() |
| 676 | return nil |
| 677 | default: |
| 678 | } |
| 679 | close(c.closed) |
| 680 | c.telemetryWg.Wait() |
| 681 | c.mutex.Unlock() |
| 682 | |
| 683 | var wg sync.WaitGroup |
| 684 | defer wg.Wait() |
| 685 | |
| 686 | if c.trafficStats != nil { |
| 687 | wg.Add(1) |
| 688 | go func() { |
| 689 | defer wg.Done() |
| 690 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 691 | defer cancel() |
| 692 | _ = c.trafficStats.Shutdown(ctx) |
| 693 | }() |
| 694 | } |
| 695 | |
| 696 | _ = c.netStack.Close() |
| 697 | c.logger.Debug(context.Background(), "closed netstack") |
| 698 | _ = c.wireguardMonitor.Close() |
| 699 | _ = c.dialer.Close() |
| 700 | // Stops internals, e.g. tunDevice, magicConn and dnsManager. |
| 701 | c.wireguardEngine.Close() |
| 702 | |
| 703 | c.mutex.Lock() |
| 704 | for _, l := range c.listeners { |
| 705 | _ = l.closeNoLock() |
| 706 | } |
| 707 | c.listeners = nil |
| 708 | c.mutex.Unlock() |
| 709 | |
| 710 | return nil |
| 711 | } |
| 712 | |
| 713 | func (c *Conn) isClosed() bool { |
| 714 | select { |