Skip to content

Commit

Permalink
Imp: make sure that client request sequence is an odd number
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks committed Mar 2, 2020
1 parent 039e12f commit c76c856
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions protocol/dubbo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package dubbo

import (
"math/rand"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -83,6 +84,8 @@ func init() {
return
}
setClientGrpool()

rand.Seed(time.Now().UnixNano())
}

// SetClientConf ...
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions protocol/dubbo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c76c856

Please sign in to comment.