MCPcopy Index your code
hub / github.com/coder/coder / Close

Method Close

tailnet/conn.go:667–711  ·  view source on GitHub ↗

Close shuts down the Wireguard connection.

()

Source from the content-addressed store, hash-verified

665
666// Close shuts down the Wireguard connection.
667func (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
713func (c *Conn) isClosed() bool {
714 select {

Callers 6

TestTailnetFunction · 0.95
TestConn_PreferredDERPFunction · 0.95
TestConn_UpdateDERPFunction · 0.95
TestConn_BlockEndpointsFunction · 0.95
NewConnFunction · 0.95
startClientOptionsFunction · 0.95

Implementers 1

fakeConnvpn/tunnel_internal_test.go

Calls 10

closeNoLockMethod · 0.80
closeMethod · 0.65
WaitMethod · 0.65
AddMethod · 0.65
ShutdownMethod · 0.65
CloseMethod · 0.65
InfoMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
DoneMethod · 0.45

Tested by 4

TestTailnetFunction · 0.76
TestConn_PreferredDERPFunction · 0.76
TestConn_UpdateDERPFunction · 0.76
TestConn_BlockEndpointsFunction · 0.76