diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index 0765a330b534b4f88a955d1ab898780e9fa60713..5ec7db51af0ddfa6e49d3c65910355f0bf2de414 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 430c4e49d81d4d5d151a545e1a130fd4ac3fbdc5..0251b78a2b0d27a68461c16c284b1af53bcb08aa 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 }