fix: agent panics on closed network (#5295)

* fix: agent panics on closed network

* Remove a.network = network

* Fix

* Fix

* Fix
This commit is contained in:
Marcin Tojek
2022-12-05 23:18:23 +01:00
committed by GitHub
parent 061635c36d
commit d3200382f6
+2 -3
View File
@@ -245,13 +245,13 @@ func (a *agent) trackConnGoroutine(fn func()) error {
return nil
}
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (network *tailnet.Conn, err error) {
func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (_ *tailnet.Conn, err error) {
a.closeMutex.Lock()
if a.isClosed() {
a.closeMutex.Unlock()
return nil, xerrors.New("closed")
}
network, err = tailnet.NewConn(&tailnet.Options{
network, err := tailnet.NewConn(&tailnet.Options{
Addresses: []netip.Prefix{netip.PrefixFrom(codersdk.TailnetIP, 128)},
DERPMap: derpMap,
Logger: a.logger.Named("tailnet"),
@@ -266,7 +266,6 @@ func (a *agent) createTailnet(ctx context.Context, derpMap *tailcfg.DERPMap) (ne
network.Close()
}
}()
a.network = network
a.closeMutex.Unlock()
sshListener, err := network.Listen("tcp", ":"+strconv.Itoa(codersdk.TailnetSSHPort))