Skip to content

Commit

Permalink
fix HeartbeatCodec may be make so many goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
snail007 committed Feb 3, 2025
1 parent 15394fe commit 0bf1bbb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions util/net/heartbeat_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type HeartbeatCodec struct {
ctxCancel context.CancelFunc
readPool *gpool.Pool
writePool *gpool.Pool
writeHbPool *gpool.Pool
}

func (s *HeartbeatCodec) sendReadErr(err error) {
Expand Down Expand Up @@ -253,7 +254,11 @@ func (s *HeartbeatCodec) Write(b []byte) (n int, err error) {
msg := newHeartbeatCodecMsg()
msg.SetData(b)
done := make(chan bool)
s.writePool.Submit(func() {
p := s.writePool
if len(b) == 0 {
p = s.writeHbPool
}
p.Submit(func() {
defer func() {
close(done)
//put msg buffer back to pool
Expand Down Expand Up @@ -312,8 +317,9 @@ func (s *HeartbeatCodec) Initialize(ctx Context) (err error) {
}
s.readErrChn = make(chan error, 1)
s.writeErrChn = make(chan error, 1)
s.readPool = gpool.New(2)
s.writePool = gpool.New(2)
s.readPool = gpool.New(1)
s.writePool = gpool.New(1)
s.writeHbPool = gpool.New(1)
s.ctx, s.ctxCancel = context.WithCancel(context.Background())
go s.backgroundRead()
go s.heartbeat()
Expand Down

0 comments on commit 0bf1bbb

Please sign in to comment.