Skip to content

Commit

Permalink
Refactor getty.
Browse files Browse the repository at this point in the history
Co-authored-by: marsevilspirit <[email protected]>
Co-authored-by: solisamicus <[email protected]>
Co-authored-by: No-SilverBullet  <[email protected]>
  • Loading branch information
4 people committed Dec 20, 2024
1 parent 001e49c commit 51d1cae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/remoting/getty/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ func (g *gettyClientHandler) OnCron(session getty.Session) {
err := g.transferHeartBeat(session, message.HeartBeatMessagePing)
if err != nil {
log.Warnf("failed to send heart beat: {%#v}", err.Error())
if session.GetAttribute(heartBeatRetryTimes) != nil {
retryTimes := session.GetAttribute(heartBeatRetryTimes).(int)
if session.GetAttribute(heartBeatRetryTimesKey) != nil {
retryTimes := session.GetAttribute(heartBeatRetryTimesKey).(int)
if retryTimes >= maxHeartBeatRetryTimes {
log.Warnf("heartbeat retry times exceed default max times{%d}, close the session{%s}",
log.Warnf("heartbeat retry times exceed default max retry times{%d}, close the session{%s}",
maxHeartBeatRetryTimes, session.Stat())
sessionManager.releaseSession(session)
return
}
session.SetAttribute(heartBeatRetryTimes, retryTimes+1)
session.SetAttribute(heartBeatRetryTimesKey, retryTimes+1)
} else {
session.SetAttribute(heartBeatRetryTimes, 1)
session.SetAttribute(heartBeatRetryTimesKey, 1)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/remoting/getty/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
const (
maxCheckAliveRetry = 600
checkAliveInternal = 100
heartBeatRetryTimes = "heartbeat-retry-times"
heartBeatRetryTimesKey = "heartbeat-retry-times"
maxHeartBeatRetryTimes = 3
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func (g *SessionManager) setSessionConfig(session getty.Session) {
session.SetWriteTimeout(g.gettyConf.SessionConfig.TCPWriteTimeout)
session.SetCronPeriod((int)(g.gettyConf.SessionConfig.CronPeriod.Milliseconds()))
session.SetWaitTime(g.gettyConf.SessionConfig.WaitTimeout)
session.SetAttribute(heartBeatRetryTimes, 0)
session.SetAttribute(heartBeatRetryTimesKey, 0)
}

func (g *SessionManager) newSession(session getty.Session) error {
Expand Down

0 comments on commit 51d1cae

Please sign in to comment.