Skip to content

Commit

Permalink
feat: close the network if its send is at max capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
liurunzhi committed May 25, 2023
1 parent c51e0d4 commit 177d08b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ func (a *agentImpl) send(pendingMsg pendingMessage) (err error) {
}()
a.reportChannelSize()

if chSendCapacity := a.messagesBufferSize - len(a.chSend); chSendCapacity == 0 {
logger.Log.Warnf("the agent is will close as its network is busy, ID=%d, UID=%s",
a.Session.ID(), a.Session.UID())
a.Close()
return nil
}

m, err := a.getMessageFromPendingMessage(pendingMsg)
if err != nil {
return err
Expand Down Expand Up @@ -616,7 +623,7 @@ func hbdEncode(heartbeatTimeout time.Duration, packetEncoder codec.PacketEncoder
func (a *agentImpl) reportChannelSize() {
chSendCapacity := a.messagesBufferSize - len(a.chSend)
if chSendCapacity == 0 {
logger.Log.Warnf("chSend is at maximum capacity")
logger.Log.Warnf("chSend is at maximum capacity, ID=%d, UID=%s", a.Session.ID(), a.Session.UID())
}
for _, mr := range a.metricsReporters {
if err := mr.ReportGauge(metrics.ChannelCapacity, map[string]string{"channel": "agent_chsend"}, float64(chSendCapacity)); err != nil {
Expand Down

0 comments on commit 177d08b

Please sign in to comment.