You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2020/03/11 11:24:22 UTC
[rocketmq-client-go] branch native updated: fix(producer):
UpdateNameServerAddress shoule be called before producer start,
or namesrvs list will be empty, lead to a panic (#445)
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch native
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git
The following commit(s) were added to refs/heads/native by this push:
new 1ce9fd9 fix(producer): UpdateNameServerAddress shoule be called before producer start, or namesrvs list will be empty, lead to a panic (#445)
1ce9fd9 is described below
commit 1ce9fd9c6cb6648f991df95531b974e202a05d9f
Author: hzjiangjian <ji...@126.com>
AuthorDate: Wed Mar 11 19:24:13 2020 +0800
fix(producer): UpdateNameServerAddress shoule be called before producer start, or namesrvs list will be empty, lead to a panic (#445)
* fix(producer): UpdateNameServerAddress shoule be called before producer start, or namesrvs list will be empty, lead to a panic
* fix(producer): log topic name when queryTopicRouteInfoFromServer failed
---
internal/route.go | 12 ++++++++++++
producer/producer.go | 4 ++++
2 files changed, 16 insertions(+)
diff --git a/internal/route.go b/internal/route.go
index a1a3f79..09b6e53 100644
--- a/internal/route.go
+++ b/internal/route.go
@@ -339,6 +339,16 @@ func (s *namesrvs) queryTopicRouteInfoFromServer(topic string) (*TopicRouteData,
response *remote.RemotingCommand
err error
)
+
+ //if s.Size() == 0, response will be nil, lead to panic below.
+ if s.Size() == 0 {
+ rlog.Error("namesrv list empty. UpdateNameServerAddress should be called first.", map[string]interface{}{
+ "namesrv": s,
+ "topic": topic,
+ })
+ return nil, primitive.NewRemotingErr("namesrv list empty")
+ }
+
for i := 0; i < s.Size(); i++ {
rc := remote.NewRemotingCommand(ReqGetRouteInfoByTopic, request, nil)
ctx, _ := context.WithTimeout(context.Background(), requestTimeout)
@@ -351,6 +361,7 @@ func (s *namesrvs) queryTopicRouteInfoFromServer(topic string) (*TopicRouteData,
if err != nil {
rlog.Error("connect to namesrv failed.", map[string]interface{}{
"namesrv": s,
+ "topic": topic,
})
return nil, primitive.NewRemotingErr(err.Error())
}
@@ -366,6 +377,7 @@ func (s *namesrvs) queryTopicRouteInfoFromServer(topic string) (*TopicRouteData,
if err != nil {
rlog.Warning("decode TopicRouteData error: %s", map[string]interface{}{
rlog.LogKeyUnderlayError: err,
+ "topic": topic,
})
return nil, err
}
diff --git a/producer/producer.go b/producer/producer.go
index edddf90..e22cee9 100644
--- a/producer/producer.go
+++ b/producer/producer.go
@@ -80,6 +80,10 @@ func NewDefaultProducer(opts ...Option) (*defaultProducer, error) {
func (p *defaultProducer) Start() error {
atomic.StoreInt32(&p.state, int32(internal.StateRunning))
+ if len(p.options.NameServerAddrs) == 0 {
+ p.options.Namesrv.UpdateNameServerAddress(p.options.NameServerDomain, p.options.InstanceName)
+ }
+
p.client.RegisterProducer(p.group, p)
p.client.Start()
return nil