Skip to content

Commit

Permalink
Merge pull request #321 from aceld/fix/channel-close
Browse files Browse the repository at this point in the history
fix(connection): move close msgBuffChan to write side to avoid send t…
  • Loading branch information
aceld authored May 22, 2024
2 parents 2d74fdc + fd205f9 commit b85b4b5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions znet/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"sync/atomic"
"time"

"github.com/gorilla/websocket"

"github.com/aceld/zinx/zconf"
"github.com/aceld/zinx/zinterceptor"
"github.com/aceld/zinx/zlog"
"github.com/aceld/zinx/zpack"
"github.com/gorilla/websocket"

"github.com/aceld/zinx/ziface"
)
Expand Down Expand Up @@ -388,6 +389,8 @@ func (c *Connection) SendToQueue(data []byte) error {
// Send timeout
select {
case <-c.ctx.Done():
// Close all channels associated with the connection
close(c.msgBuffChan)
return errors.New("connection closed when send buff msg")
case <-idleTimeout.C:
return errors.New("send buff msg timeout")
Expand Down Expand Up @@ -479,11 +482,6 @@ func (c *Connection) finalizer() {
c.connManager.Remove(c)
}

// Close all channels associated with the connection
if c.msgBuffChan != nil {
close(c.msgBuffChan)
}

go func() {
defer func() {
if err := recover(); err != nil {
Expand Down

0 comments on commit b85b4b5

Please sign in to comment.