You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/ipn
Alex Chan b38dd1ae06 ipn/ipnlocal: don't panic if there are no suitable exit nodes
In suggestExitNodeLocked, if no exit node candidates have a home DERP or
valid location info, `bestCandidates` is an empty slice. This slice is
passed to `selectNode` (`randomNode` in prod):

```go func randomNode(nodes views.Slice[tailcfg.NodeView], …) tailcfg.NodeView {
	…
	return nodes.At(rand.IntN(nodes.Len()))
}
```

An empty slice becomes a call to `rand.IntN(0)`, which panics.

This patch changes the behaviour, so if we've filtered out all the
candidates before calling `selectNode`, reset the list and then pick
from any of the available candidates.

This patch also updates our tests to give us more coverage of `randomNode`,
so we can spot other potential issues.

Updates #17661

Change-Id: I63eb5e4494d45a1df5b1f4b1b5c6d5576322aa72
Signed-off-by: Alex Chan <alexc@tailscale.com>
1 week ago
..
auditlog syncs: add Mutex/RWMutex alias/wrappers for future mutex debugging 2 weeks ago
conffile cmd/tailscale/cli,ipn/conffile: add declarative config mode for Services (#17435) 2 months ago
desktop go.mod: bump golang.org/x/crypto (#17907) 2 weeks ago
ipnauth all: use buildfeature constants in a few more places 2 months ago
ipnext ipn/ipnlocal: remove all the weird locking (LockedOnEntry, UnlockEarly, etc) 3 weeks ago
ipnlocal ipn/ipnlocal: don't panic if there are no suitable exit nodes 1 week ago
ipnserver feature/featuretags, all: add build features, use existing ones in more places 2 months ago
ipnstate cmd/tailscale, ipn/ipnstate, wgengine/magicsock: update ping output for peer relay (#16515) 5 months ago
lapitest various: allow tailscaled shutdown via LocalAPI 2 months ago
localapi cmd/tailscaled,ipn: show a health warning when state store fails to open (#17883) 2 weeks ago
policy ipn,tailconfig: clean up unreleased and removed app connector service 2 years ago
store ipn/store, feature/condregister: permit callers to empty import optonal ipn stores 2 months ago
backend.go types/netmap: remove PrivateKey from NetworkMap 2 weeks ago
backend_test.go ipn: fix the string representation of an empty ipn.Notify 3 months ago
conf.go ipn: ensure that conffile is source of truth for advertised services. (#15361) 9 months ago
doc.go ipn: generate LoginProfileView and use it instead of *LoginProfile where appropriate 10 months ago
ipn_clone.go cmd/tailscale,feature/relayserver,ipn: add relay-server-static-endpoints set flag 1 week ago
ipn_test.go all: do not depend on the testing package 2 years ago
ipn_view.go cmd/tailscale,feature/relayserver,ipn: add relay-server-static-endpoints set flag 1 week ago
prefs.go cmd/tailscale,feature/relayserver,ipn: add relay-server-static-endpoints set flag 1 week ago
prefs_test.go cmd/tailscale,feature/relayserver,ipn: add relay-server-static-endpoints set flag 1 week ago
serve.go ipn/ipnlocal: add validations when setting serve config (#17950) 2 weeks ago
serve_test.go cmd/tailscale/cli: allow remote target as service destination (#17607) 2 weeks ago
store.go cmd/tailscaled,ipn: show a health warning when state store fails to open (#17883) 2 weeks ago
store_test.go ipn/store: automatically migrate between plaintext and encrypted state (#16318) 5 months ago