diff --git a/transport/internet/kcp/connection.go b/transport/internet/kcp/connection.go index 56dac8ace..93b9b841b 100644 --- a/transport/internet/kcp/connection.go +++ b/transport/internet/kcp/connection.go @@ -358,6 +358,9 @@ func (this *Connection) MarkPeerClose() { if this.state == ConnStateActive { this.state = ConnStatePeerClosed } + this.kcpAccess.Lock() + this.kcp.ClearSendQueue() + this.kcpAccess.Unlock() } func (this *Connection) kcpInput(data []byte) { diff --git a/transport/internet/kcp/kcp.go b/transport/internet/kcp/kcp.go index bf4df0e99..65d96ffda 100644 --- a/transport/internet/kcp/kcp.go +++ b/transport/internet/kcp/kcp.go @@ -842,3 +842,16 @@ func (kcp *KCP) WndSize(sndwnd, rcvwnd int) int { func (kcp *KCP) WaitSnd() int { return len(kcp.snd_buf) + len(kcp.snd_queue) } + +func (this *KCP) ClearSendQueue() { + for _, seg := range this.snd_queue { + seg.Release() + } + this.snd_queue = nil + + for _, seg := range this.snd_buf { + seg.Release() + } + + this.snd_buf = nil +}