Skip to content

Commit

Permalink
set default of SendResult.Status and fix panic (#495)
Browse files Browse the repository at this point in the history
* 1. send the default value of SendResult.Status to SendUnknownError
2. fix panic: select queue with nil
  • Loading branch information
dbl-x committed Jun 2, 2020
1 parent 4148bac commit 1fb7d33
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (td *traceDispatcher) sendTraceDataByMQ(keySet Keyset, regionID string, dat
var req = td.buildSendRequest(mq, msg)
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
err := td.cli.InvokeAsync(ctx, addr, req, func(command *remote.RemotingCommand, e error) {
resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if e != nil {
rlog.Info("send trace data error.", map[string]interface{}{
"traceData": data,
Expand Down
4 changes: 4 additions & 0 deletions primitive/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ type SendResult struct {
TraceOn bool
}

func NewSendResult() *SendResult {
return &SendResult{Status: SendUnknownError}
}

// SendResult send message result to string(detail result)
func (result *SendResult) String() string {
return fmt.Sprintf("SendResult [sendStatus=%d, msgIds=%s, offsetMsgId=%s, queueOffset=%d, messageQueue=%s]",
Expand Down
6 changes: 3 additions & 3 deletions producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (p *defaultProducer) SendSync(ctx context.Context, msgs ...*primitive.Messa

msg := p.encodeBatch(msgs...)

resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if p.interceptor != nil {
primitive.WithMethod(ctx, primitive.SendSync)
producerCtx := &primitive.ProducerCtx{
Expand Down Expand Up @@ -245,7 +245,7 @@ func (p *defaultProducer) sendAsync(ctx context.Context, msg *primitive.Message,

ctx, _ = context.WithTimeout(ctx, 3*time.Second)
return p.client.InvokeAsync(ctx, addr, p.buildSendRequest(mq, msg), func(command *remote.RemotingCommand, err error) {
resp := new(primitive.SendResult)
resp := primitive.NewSendResult()
if err != nil {
h(ctx, nil, err)
} else {
Expand Down Expand Up @@ -366,7 +366,7 @@ func (p *defaultProducer) selectMessageQueue(msg *primitive.Message) *primitive.
return nil
}

if result.MqList != nil && len(result.MqList) <= 0 {
if len(result.MqList) <= 0 {
rlog.Error("can not find proper message queue", nil)
return nil
}
Expand Down

0 comments on commit 1fb7d33

Please sign in to comment.