Skip to content
Snippets Groups Projects
Commit c76c8565 authored by alexstocks's avatar alexstocks
Browse files

Imp: make sure that client request sequence is an odd number

parent 039e12f0
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package dubbo package dubbo
import ( import (
"math/rand"
"strings" "strings"
"sync" "sync"
"time" "time"
...@@ -83,6 +84,8 @@ func init() { ...@@ -83,6 +84,8 @@ func init() {
return return
} }
setClientGrpool() setClientGrpool()
rand.Seed(time.Now().UnixNano())
} }
// SetClientConf ... // SetClientConf ...
...@@ -147,11 +150,18 @@ func NewClient(opt Options) *Client { ...@@ -147,11 +150,18 @@ func NewClient(opt Options) *Client {
opt.RequestTimeout = 3 * time.Second 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{ c := &Client{
opts: opt, opts: opt,
pendingResponses: new(sync.Map), pendingResponses: new(sync.Map),
conf: *clientConf, conf: *clientConf,
} }
c.sequence.Store(initSequence)
c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL)) c.pool = newGettyRPCClientConnPool(c, clientConf.PoolSize, time.Duration(int(time.Second)*clientConf.PoolTTL))
return c return c
......
...@@ -124,6 +124,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) { ...@@ -124,6 +124,7 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) {
pendingResponse := h.conn.pool.rpcClient.removePendingResponse(SequenceType(p.Header.ID)) pendingResponse := h.conn.pool.rpcClient.removePendingResponse(SequenceType(p.Header.ID))
if pendingResponse == nil { if pendingResponse == nil {
logger.Errorf("failed to get pending response context for response package %s", *p)
return return
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment