From b15c0d13a021120a80930143fe9767b28192522f Mon Sep 17 00:00:00 2001 From: xtaci Date: Wed, 28 Aug 2024 13:49:21 +0800 Subject: [PATCH] fix https://github.com/xtaci/kcp-go/issues/273 --- sess.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sess.go b/sess.go index 40e207e1..9e055b8f 100644 --- a/sess.go +++ b/sess.go @@ -610,6 +610,7 @@ func (s *UDPSession) Control(f func(conn net.PacketConn) error) error { func (s *UDPSession) postProcess() { txqueue := make([]ipv4.Message, 0, acceptBacklog) chCork := make(chan struct{}, 1) + chDie := s.die for { select { @@ -668,6 +669,9 @@ func (s *UDPSession) postProcess() { } } + // re-enable die channel + chDie = s.die + case <-chCork: // emulate a corked socket if len(txqueue) > 0 { s.tx(txqueue) @@ -679,7 +683,15 @@ func (s *UDPSession) postProcess() { txqueue = txqueue[:0] } - case <-s.die: + // re-enable die channel + chDie = s.die + + case <-chDie: + // remaining packets in txqueue should be sent out + if len(chCork) > 0 || len(s.chPostProcessing) > 0 { + chDie = nil // block chDie temporarily + continue + } return } }