Fix relay migration panic by covering every possible relay state (#1414)

This commit is contained in:
brad-defined 2025-07-02 08:48:02 -04:00 committed by GitHub
parent b158eb0c4c
commit 94142aded5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/binary" "encoding/binary"
"fmt"
"net/netip" "net/netip"
"sync" "sync"
"time" "time"
@ -227,21 +228,25 @@ func (n *connectionManager) migrateRelayUsed(oldhostinfo, newhostinfo *HostInfo)
var relayFrom netip.Addr var relayFrom netip.Addr
var relayTo netip.Addr var relayTo netip.Addr
switch { switch {
case ok && existing.State == Established: case ok:
// This relay already exists in newhostinfo, then do nothing. switch existing.State {
continue case Established, PeerRequested, Disestablished:
case ok && existing.State == Requested: // This relay already exists in newhostinfo, then do nothing.
// The relay exists in a Requested state; re-send the request continue
index = existing.LocalIndex case Requested:
switch r.Type { // The relay exists in a Requested state; re-send the request
case TerminalType: index = existing.LocalIndex
relayFrom = n.intf.myVpnAddrs[0] switch r.Type {
relayTo = existing.PeerAddr case TerminalType:
case ForwardingType: relayFrom = n.intf.myVpnAddrs[0]
relayFrom = existing.PeerAddr relayTo = existing.PeerAddr
relayTo = newhostinfo.vpnAddrs[0] case ForwardingType:
default: relayFrom = existing.PeerAddr
// should never happen relayTo = newhostinfo.vpnAddrs[0]
default:
// should never happen
panic(fmt.Sprintf("Migrating unknown relay type: %v", r.Type))
}
} }
case !ok: case !ok:
n.relayUsedLock.RLock() n.relayUsedLock.RLock()
@ -267,6 +272,7 @@ func (n *connectionManager) migrateRelayUsed(oldhostinfo, newhostinfo *HostInfo)
relayTo = newhostinfo.vpnAddrs[0] relayTo = newhostinfo.vpnAddrs[0]
default: default:
// should never happen // should never happen
panic(fmt.Sprintf("Migrating unknown relay type: %v", r.Type))
} }
} }