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 @@
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
......
......@@ -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
}
......
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