Skip to content

Commit 8e4197d

Browse files
authored
解决服务实例同步健康状态不一致问题 (#913)
1 parent 65fd429 commit 8e4197d

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

apiserver/eurekaserver/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func (h *EurekaServer) Run(errCh chan error) {
305305
} else {
306306
err = server.ServeTLS(ln, h.tlsInfo.CertFile, h.tlsInfo.KeyFile)
307307
}
308-
if err != nil {
308+
if err != nil && err != http.ErrServerClosed {
309309
log.Errorf("%+v", err)
310310
if !h.restart {
311311
log.Infof("not in restart progress, broadcast error")

bootstrap/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ func SelfDeregister() {
581581
log.Errorf("Deregister instance error: %s", resp.GetInfo().GetValue())
582582
}
583583
}
584+
// wait the async event handler to finish
585+
time.Sleep(5 * time.Second)
584586
}
585587

586588
// getLocalHost 获取本地IP地址

cache/client.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@ func doClientPage(ret []*model.Client, offset, limit uint32) []*model.Client {
304304
endIndex = totalCount
305305
}
306306

307-
for i := range ret {
308-
clients = append(clients, ret[i])
309-
}
307+
clients = append(clients, ret...)
310308

311309
sort.Slice(clients, func(i, j int) bool {
312310
return clients[i].ModifyTime().After(clients[j].ModifyTime())

common/model/naming.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,15 @@ func (i *InstanceEvent) InjectMetadata(ctx context.Context) {
530530
i.MetaData = value.(map[string]string)
531531
}
532532

533+
func (i *InstanceEvent) String() string {
534+
if nil == i {
535+
return "nil"
536+
}
537+
hostPortStr := fmt.Sprintf("%s:%d", i.Instance.GetHost().GetValue(), i.Instance.GetPort().GetValue())
538+
return fmt.Sprintf("InstanceEvent(id=%s, namespace=%s, service=%s, type=%v, instance=%s, healthy=%v)",
539+
i.Id, i.Namespace, i.Service, i.EType, hostPortStr, i.Instance.GetHealthy().GetValue())
540+
}
541+
533542
// InstanceCount Service instance statistics
534543
type InstanceCount struct {
535544
// HealthyInstanceCount 健康实例数

service/instance.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ func (s *Server) CreateInstance(ctx context.Context, req *api.Instance) *api.Res
114114
Name: req.GetService().GetValue(),
115115
Namespace: req.GetNamespace().GetValue(),
116116
}
117+
instanceProto := data.Proto
117118
event := &model.InstanceEvent{
118119
Id: instanceID,
119120
Namespace: svc.Namespace,
120121
Service: svc.Name,
121-
Instance: &ins,
122+
Instance: instanceProto,
122123
EType: model.EventInstanceOnline,
123124
CreateTime: time.Time{},
124125
}
@@ -127,11 +128,11 @@ func (s *Server) CreateInstance(ctx context.Context, req *api.Instance) *api.Res
127128
s.RecordHistory(instanceRecordEntry(ctx, svc, data, model.OCreate))
128129
out := &api.Instance{
129130
Id: ins.GetId(),
130-
Service: req.GetService(),
131-
Namespace: req.GetNamespace(),
132-
VpcId: req.GetVpcId(),
133-
Host: req.GetHost(),
134-
Port: req.GetPort(),
131+
Service: &wrappers.StringValue{Value: svc.Name},
132+
Namespace: &wrappers.StringValue{Value: svc.Namespace},
133+
VpcId: instanceProto.GetVpcId(),
134+
Host: instanceProto.GetHost(),
135+
Port: instanceProto.GetPort(),
135136
}
136137
return api.NewInstanceResponse(api.ExecuteSuccess, out)
137138
}

0 commit comments

Comments
 (0)