diff --git a/go.mod b/go.mod index 1df8b24..cbdb6d0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/urfave/cli v1.22.12 github.com/xtaci/kcp-go/v5 v5.6.2 - github.com/xtaci/smux v1.5.19 + github.com/xtaci/smux v1.5.20 github.com/xtaci/tcpraw v1.2.25 golang.org/x/crypto v0.5.0 ) diff --git a/go.sum b/go.sum index 49e9e59..e76b973 100644 --- a/go.sum +++ b/go.sum @@ -74,6 +74,8 @@ github.com/xtaci/smux v1.5.18 h1:NRH2dIxcO1w5dsNpQxSrxfhxjk4YNg6TrS/Nj0FuUPc= github.com/xtaci/smux v1.5.18/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY= github.com/xtaci/smux v1.5.19 h1:QFoVBZPuJnoTs8QQ52TO2469nz8KxGHDpiEb+s3QzCQ= github.com/xtaci/smux v1.5.19/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY= +github.com/xtaci/smux v1.5.20 h1:7pw7PLSW1MfiiRVBB27T5cFLGws1GAJP9ZDP+V+40dw= +github.com/xtaci/smux v1.5.20/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY= github.com/xtaci/tcpraw v1.2.25 h1:VDlqo0op17JeXBM6e2G9ocCNLOJcw9mZbobMbJjo0vk= github.com/xtaci/tcpraw v1.2.25/go.mod h1:dKyZ2V75s0cZ7cbgJYdxPvms7af0joIeOyx1GgJQbLk= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= diff --git a/vendor/github.com/xtaci/smux/session.go b/vendor/github.com/xtaci/smux/session.go index 4659743..28fdd04 100644 --- a/vendor/github.com/xtaci/smux/session.go +++ b/vendor/github.com/xtaci/smux/session.go @@ -13,6 +13,7 @@ import ( const ( defaultAcceptBacklog = 1024 + maxShaperSize = 1024 ) var ( @@ -420,8 +421,10 @@ func (s *Session) shaperLoop() { var reqs shaperHeap var next writeRequest var chWrite chan writeRequest + var chShaper chan writeRequest for { + // chWrite is not available until it has packet to send if len(reqs) > 0 { chWrite = s.writes next = heap.Pop(&reqs).(writeRequest) @@ -429,10 +432,22 @@ func (s *Session) shaperLoop() { chWrite = nil } + // control heap size, chShaper is not available until packets are less than maximum allowed + if len(reqs) >= maxShaperSize { + chShaper = nil + } else { + chShaper = s.shaper + } + + // assertion on non nil + if chShaper == nil && chWrite == nil { + panic("both channel are nil") + } + select { case <-s.die: return - case r := <-s.shaper: + case r := <-chShaper: if chWrite != nil { // next is valid, reshape heap.Push(&reqs, next) } diff --git a/vendor/github.com/xtaci/smux/stream.go b/vendor/github.com/xtaci/smux/stream.go index a95fb56..94e858e 100644 --- a/vendor/github.com/xtaci/smux/stream.go +++ b/vendor/github.com/xtaci/smux/stream.go @@ -325,7 +325,7 @@ func (s *Stream) Write(b []byte) (n int, err error) { } frame.data = bts[:sz] bts = bts[sz:] - n, err := s.sess.writeFrameInternal(frame, deadline, s.numWritten) + n, err := s.sess.writeFrameInternal(frame, deadline, 0) s.numWritten++ sent += n if err != nil { @@ -393,7 +393,7 @@ func (s *Stream) writeV2(b []byte) (n int, err error) { } frame.data = bts[:sz] bts = bts[sz:] - n, err := s.sess.writeFrameInternal(frame, deadline, atomic.LoadUint32(&s.numWritten)) + n, err := s.sess.writeFrameInternal(frame, deadline, 0) atomic.AddUint32(&s.numWritten, uint32(sz)) sent += n if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 6ee3e06..6308e78 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -38,7 +38,7 @@ github.com/urfave/cli # github.com/xtaci/kcp-go/v5 v5.6.2 ## explicit; go 1.13 github.com/xtaci/kcp-go/v5 -# github.com/xtaci/smux v1.5.19 +# github.com/xtaci/smux v1.5.20 ## explicit; go 1.13 github.com/xtaci/smux # github.com/xtaci/tcpraw v1.2.25