Skip to content

Commit

Permalink
feat:update to dubbo-getty-v1.4.12
Browse files Browse the repository at this point in the history
  • Loading branch information
No-SilverBullet committed May 29, 2024
1 parent 23efee8 commit 154ad97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
18 changes: 12 additions & 6 deletions transport/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,10 @@ func (c *client) RunEventLoop(newSession NewSessionCallback) {

// a for-loop connect to make sure the connection pool is valid
func (c *client) reConnect() {
var num, max, times, interval int

var (
num, max, times, interval int
maxDuration int64
)
max = c.number
interval = c.reconnectInterval
if interval == 0 {
Expand All @@ -436,15 +438,18 @@ func (c *client) reConnect() {
}

num = c.sessionNum()
if max <= num {
if max <= num || max < times {
//Exit when the number of connection pools is sufficient or the reconnection times exceeds the connections numbers.
break
}
c.connect()
times++
if maxTimes < times {
times = maxTimes
if times > maxTimes {
maxDuration = int64(maxTimes) * int64(interval)
} else {
maxDuration = int64(times) * int64(interval)
}
<-gxtime.After(time.Duration(int64(times) * int64(interval)))
<-gxtime.After(time.Duration(maxDuration))
}
}

Expand All @@ -458,6 +463,7 @@ func (c *client) stop() {
c.Lock()
for s := range c.ssMap {
s.RemoveAttribute(sessionClientKey)
s.RemoveAttribute(ignoreReconnectKey)
s.Close()
}
c.ssMap = nil
Expand Down
12 changes: 6 additions & 6 deletions transport/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestTCPClient(t *testing.T) {
assert.True(t, conn.compress == CompressNone)
beforeWriteBytes := conn.writeBytes
beforeWritePkgNum := conn.writePkgNum
l, err := conn.send([]byte("hello"))
l, err := conn.Send([]byte("hello"))
assert.Nil(t, err)
assert.True(t, l == 5)
beforeWritePkgNum.Add(1)
Expand All @@ -156,7 +156,7 @@ func TestTCPClient(t *testing.T) {
assert.Equal(t, beforeWritePkgNum, conn.writePkgNum)
var pkgs [][]byte
pkgs = append(pkgs, []byte("hello"), []byte("hello"))
l, err = conn.send(pkgs)
l, err = conn.Send(pkgs)
assert.Nil(t, err)
assert.True(t, l == 10)
beforeWritePkgNum.Add(2)
Expand Down Expand Up @@ -275,11 +275,11 @@ func TestUDPClient(t *testing.T) {
}
t.Logf("udp context:%s", udpCtx)
udpConn := ss.(*session).Connection.(*gettyUDPConn)
_, err = udpConn.send(udpCtx)
_, err = udpConn.Send(udpCtx)
assert.NotNil(t, err)
udpCtx.Pkg = []byte("hello")
beforeWriteBytes := udpConn.writeBytes
_, err = udpConn.send(udpCtx)
_, err = udpConn.Send(udpCtx)
beforeWriteBytes.Add(5)
assert.Equal(t, beforeWriteBytes, udpConn.writeBytes)
assert.Nil(t, err)
Expand Down Expand Up @@ -338,7 +338,7 @@ func TestNewWSClient(t *testing.T) {
assert.True(t, conn.compress == CompressNone)
err := conn.handlePing("hello")
assert.Nil(t, err)
l, err := conn.send("hello")
l, err := conn.Send("hello")
assert.NotNil(t, err)
assert.True(t, l == 0)
ss.SetSession(ss)
Expand All @@ -347,7 +347,7 @@ func TestNewWSClient(t *testing.T) {
active := ss.GetActive()
assert.NotNil(t, active)
beforeWriteBytes := conn.writeBytes
_, err = conn.send([]byte("hello"))
_, err = conn.Send([]byte("hello"))
assert.Nil(t, err)
beforeWriteBytes.Add(5)
assert.Equal(t, beforeWriteBytes, conn.writeBytes)
Expand Down
1 change: 0 additions & 1 deletion transport/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@ func (s *session) addTask(pkg interface{}) {
log.Errorf("[Id:%d, name=%s, endpoint=%s] Session is closed", s.ID(), s.name, s.EndPoint())
return
}

s.listener.OnMessage(s, pkg)
s.IncReadPkgNum()
}
Expand Down

0 comments on commit 154ad97

Please sign in to comment.