From c76c8565e6887a7f1d8fe09e4b843b431030f40d Mon Sep 17 00:00:00 2001
From: alexstocks <alexstocks@foxmail.com>
Date: Mon, 2 Mar 2020 21:05:12 +0800
Subject: [PATCH] Imp: make sure that client request sequence is an odd number

---
 protocol/dubbo/client.go   | 10 ++++++++++
 protocol/dubbo/listener.go |  1 +
 2 files changed, 11 insertions(+)

diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go
index 0765a330b..5ec7db51a 100644
--- a/protocol/dubbo/client.go
+++ b/protocol/dubbo/client.go
@@ -18,6 +18,7 @@
 package dubbo
 
 import (
+	"math/rand"
 	"strings"
 	"sync"
 	"time"
@@ -83,6 +84,8 @@ func init() {
 		return
 	}
 	setClientGrpool()
+
+	rand.Seed(time.Now().UnixNano())
 }
 
 // SetClientConf ...
@@ -147,11 +150,18 @@ func NewClient(opt Options) *Client {
 		opt.RequestTimeout = 3 * time.Second
 	}
 
+	// make sure that client request sequence is an odd number
+	initSequence := uint64(rand.Int63n(time.Now().UnixNano()))
+	if initSequence%2 == 0 {
+		initSequence++
+	}
+
 	c := &Client{
 		opts:             opt,
 		pendingResponses: new(sync.Map),
 		conf:             *clientConf,
 	}
+	c.sequence.Store(initSequence)
 	c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
 
 	return c
diff --git a/protocol/dubbo/listener.go b/protocol/dubbo/listener.go
index 430c4e49d..0251b78a2 100644
--- a/protocol/dubbo/listener.go
+++ b/protocol/dubbo/listener.go
@@ -124,6 +124,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
 
 	pendingResponse := h.conn.pool.rpcClient.removePendingResponse(SequenceType(p.Header.ID))
 	if pendingResponse == nil {
+		logger.Errorf("failed to get pending response context for response package %s", *p)
 		return
 	}
 
-- 
GitLab