From 95b064fc55e83f98f0c155bc5514c41debbe23fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filippo=20Muscher=C3=A0?= Date: Mon, 17 Nov 2025 20:35:09 +0100 Subject: [PATCH] Fixed a bug where a double "/" would be added to the load balancers' path. The previous version would concatenate `areaEtcdKey(area) + "/" + registryLoadBalancerDirectory`. This would result in a path like: "registry/area-name//__lb" instead of the correct one "registry/area-name/__lb", since areaEtcdKey returns a "/"-terminated value". The result was that the `servers` map would always be empty, even when a load balancer was available. The fix uses path.Join(), instead of just removing the `+ "/" +`. This is because this function is more robust to errors. In fact, path.Joins returns a correct path even when the arguments are something like "a/" and "/b" (which after the fix is no longer the case, anyway). The return in this example would still be "a/b" and not "a//b", like it would happen with this bug. This should solve the bug and be more bug-resistant also for the future. --- internal/registration/registry.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/registration/registry.go b/internal/registration/registry.go index 1ab29316..8287ea59 100644 --- a/internal/registration/registry.go +++ b/internal/registration/registry.go @@ -2,9 +2,6 @@ package registration import ( "fmt" - "github.com/hexablock/vivaldi" - "github.com/serverledge-faas/serverledge/internal/node" - "golang.org/x/exp/maps" "log" "net" "path" @@ -14,6 +11,10 @@ import ( "sync" "time" + "github.com/hexablock/vivaldi" + "github.com/serverledge-faas/serverledge/internal/node" + "golang.org/x/exp/maps" + "github.com/serverledge-faas/serverledge/internal/config" "github.com/serverledge-faas/serverledge/utils" "go.etcd.io/etcd/client/v3" @@ -194,7 +195,8 @@ func GetOneNodeInArea(area string, includeSelf bool) (NodeRegistration, error) { } func GetLBInArea(area string) (map[string]NodeRegistration, error) { - baseDir := areaEtcdKey(area) + "/" + registryLoadBalancerDirectory + prefix := areaEtcdKey(area) + baseDir := path.Join(prefix, registryLoadBalancerDirectory) ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)