From 0dd723b29fea11470ad6890d033c2a24a9be79d2 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Sun, 17 Apr 2022 16:23:53 +0000 Subject: [PATCH] chore(provider): add safety connection count check --- internal/provider/utils/pick.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/provider/utils/pick.go b/internal/provider/utils/pick.go index c201ea5d..6b804b7a 100644 --- a/internal/provider/utils/pick.go +++ b/internal/provider/utils/pick.go @@ -11,6 +11,8 @@ import ( "github.com/qdm12/gluetun/internal/models" ) +var ErrNoConnectionToPickFrom = errors.New("no connection to pick from") + // PickConnection picks a connection from a pool of connections. // If the VPN protocol is Wireguard and the target IP is set, // it finds the connection corresponding to this target IP. @@ -19,6 +21,10 @@ import ( func PickConnection(connections []models.Connection, selection settings.ServerSelection, randSource rand.Source) ( connection models.Connection, err error) { + if len(connections) == 0 { + return connection, ErrNoConnectionToPickFrom + } + if len(selection.TargetIP) > 0 && selection.VPN == constants.Wireguard { // we need the right public key return getTargetIPConnection(connections, selection.TargetIP)