Skip to content

Commit 95b064f

Browse files
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.
1 parent 9020f78 commit 95b064f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

internal/registration/registry.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package registration
22

33
import (
44
"fmt"
5-
"github.com/hexablock/vivaldi"
6-
"github.com/serverledge-faas/serverledge/internal/node"
7-
"golang.org/x/exp/maps"
85
"log"
96
"net"
107
"path"
@@ -14,6 +11,10 @@ import (
1411
"sync"
1512
"time"
1613

14+
"github.com/hexablock/vivaldi"
15+
"github.com/serverledge-faas/serverledge/internal/node"
16+
"golang.org/x/exp/maps"
17+
1718
"github.com/serverledge-faas/serverledge/internal/config"
1819
"github.com/serverledge-faas/serverledge/utils"
1920
"go.etcd.io/etcd/client/v3"
@@ -194,7 +195,8 @@ func GetOneNodeInArea(area string, includeSelf bool) (NodeRegistration, error) {
194195
}
195196

196197
func GetLBInArea(area string) (map[string]NodeRegistration, error) {
197-
baseDir := areaEtcdKey(area) + "/" + registryLoadBalancerDirectory
198+
prefix := areaEtcdKey(area)
199+
baseDir := path.Join(prefix, registryLoadBalancerDirectory)
198200

199201
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
200202

0 commit comments

Comments
 (0)