fix relay migration panic (#1403)

This commit is contained in:
brad-defined 2025-05-13 14:58:58 -04:00 committed by GitHub
parent 04d7a8ccba
commit 8c29b15c6d
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,11 +228,13 @@ 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:
switch existing.State {
case Established, PeerRequested, Disestablished:
// This relay already exists in newhostinfo, then do nothing. // This relay already exists in newhostinfo, then do nothing.
continue continue
case ok && existing.State == Requested: case Requested:
// The relay exists in a Requested state; re-send the request // The relayed connection exists in a Requested state; re-send the request
index = existing.LocalIndex index = existing.LocalIndex
switch r.Type { switch r.Type {
case TerminalType: case TerminalType:
@ -242,6 +245,8 @@ func (n *connectionManager) migrateRelayUsed(oldhostinfo, newhostinfo *HostInfo)
relayTo = newhostinfo.vpnIp relayTo = newhostinfo.vpnIp
default: default:
// should never happen // 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.vpnIp relayTo = newhostinfo.vpnIp
default: default:
// should never happen // should never happen
panic(fmt.Sprintf("Migrating unknown relay type: %v", r.Type))
} }
} }