Skip to content

Commit

Permalink
fix(registry/polaris): fix concurrent map iteration and map write go-…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccheers committed Jul 31, 2024
1 parent d6fca5e commit 3f8ed37
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions contrib/polaris/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package polaris
import (
"context"
"fmt"
"maps"
"net"
"net/url"
"strconv"
Expand Down Expand Up @@ -115,15 +116,16 @@ func (r *Registry) Register(_ context.Context, instance *registry.ServiceInstanc
}

// metadata
if instance.Metadata == nil {
instance.Metadata = make(map[string]string)
rmd := maps.Clone(instance.Metadata)
if rmd == nil {
rmd = make(map[string]string)
}
instance.Metadata["merge"] = id
if _, ok := instance.Metadata["weight"]; !ok {
instance.Metadata["weight"] = strconv.Itoa(r.opt.Weight)
rmd["merge"] = id
if _, ok := rmd["weight"]; !ok {
rmd["weight"] = strconv.Itoa(r.opt.Weight)
}

weight, _ := strconv.Atoi(instance.Metadata["weight"])
weight, _ := strconv.Atoi(rmd["weight"])

_, err = r.provider.RegisterInstance(
&polaris.InstanceRegisterRequest{
Expand Down

0 comments on commit 3f8ed37

Please sign in to comment.