GithubHelp home page GithubHelp logo

V1.2.1 之后的版本有bug about smux HOT 23 CLOSED

xtaci avatar xtaci commented on August 18, 2024
V1.2.1 之后的版本有bug

from smux.

Comments (23)

f4nff avatar f4nff commented on August 18, 2024 1

@xtaci 简单的测试了下,没问题了

from smux.

xtaci avatar xtaci commented on August 18, 2024

请提供如何重现的例子

from smux.

f4nff avatar f4nff commented on August 18, 2024

起初我还以为 kcp-go有bug,但是测试了几次,发现是
smux V1.2.2 V1.2.3 有问题,

from smux.

biotooff avatar biotooff commented on August 18, 2024

copy directly into bytes.Buffer without a tmp buffer
https://github.com/xtaci/smux/commit/8a71918d00ec9d14824b26de2ebfea34c3b6190c#diff-f2fccfb96064097b73fbe8eeae3703eeR255
written, err = stream.receiveBytes(s.conn, int64(hdr.Length()))

大流量下突然关闭客户端上层链接会导致 返回 0,nil。(eg:视频切换时间轴、关闭视频页面)
数据遗留在队列中未被读取,导致下次读取数据头失败。
建议判断下written不等于datalen并丢弃数据

from smux.

f4nff avatar f4nff commented on August 18, 2024

对,就是这样,突然拖动视频,高清一些的,就会触发,

from smux.

xtaci avatar xtaci commented on August 18, 2024

之前的是ReadFull,不存在残缺数据

from smux.

xtaci avatar xtaci commented on August 18, 2024

@biotooff 应该不会返回0, nil的情况

from smux.

xtaci avatar xtaci commented on August 18, 2024

331
332 // CopyN copies n bytes (or until an error) from src to dst.
333 // It returns the number of bytes copied and the earliest
334 // error encountered while copying.
335 // On return, written == n if and only if err == nil.
336 //
337 // If dst implements the ReaderFrom interface,
338 // the copy is implemented using it.
339 func CopyN(dst Writer, src Reader, n int64) (written int64, err error) {

from smux.

cs8425 avatar cs8425 commented on August 18, 2024

我認為是cmdPSH找不到對應的stream
然後沒有把剩餘的Frame資料讀走
接著又直接回去讀取hdr造成錯誤(此時讀到的是cmdPSH的資料, 而非下個Frame)
之前的實作是一定會讀取等於hdr.Length()長度的資料
再去讀取下個Frame

from smux.

xtaci avatar xtaci commented on August 18, 2024

我猜的一个可能原因是receiveBytes如果存在下层阻塞,会导致Close和OpenStream阻塞的问题

from smux.

xtaci avatar xtaci commented on August 18, 2024

@cs8425 对的

from smux.

xtaci avatar xtaci commented on August 18, 2024

看来中间的buffer不可避免

from smux.

cs8425 avatar cs8425 commented on August 18, 2024

應該是可以避免中間buffer
只是要判斷如果沒有對應的stream
要記得把剩餘資料讀走&丟棄
(不只cmdPSH, 其他cmd理論上也有可能長度不為0..?

from smux.

biotooff avatar biotooff commented on August 18, 2024

我認為是cmdPSH找不到對應的stream
然後沒有把剩餘的Frame資料讀走
接著又直接回去讀取hdr造成錯誤(此時讀到的是cmdPSH的資料, 而非下個Frame)
之前的實作是一定會讀取等於hdr.Length()長度的資料
再去讀取下個Frame

确实

from smux.

xtaci avatar xtaci commented on August 18, 2024
254             case cmdPSH:
255                 var written int64
256                 var err error
257                 s.streamLock.Lock()
258                 if stream, ok := s.streams[sid]; ok {
259                     written, err = stream.receiveBytes(s.conn, int64(hdr.Length()))
260                     atomic.AddInt32(&s.bucket, -int32(written))
261                     stream.notifyReadEvent()
262                 } else { // discard
263                     io.CopyN(ioutil.Discard, s.conn, int64(hdr.Length()))
264                 }
265                 s.streamLock.Unlock()

from smux.

xtaci avatar xtaci commented on August 18, 2024

这样应该就ok了

from smux.

xtaci avatar xtaci commented on August 18, 2024

push了,各位测下

from smux.

biotooff avatar biotooff commented on August 18, 2024

会出现中途读取失败吗?
残余数据不一定等于datalen

from smux.

xtaci avatar xtaci commented on August 18, 2024

如果出现残余数据,说明链接也断开了,这个时候err会触发s.Close

from smux.

xtaci avatar xtaci commented on August 18, 2024

@f4nff @cs8425

from smux.

xtaci avatar xtaci commented on August 18, 2024

非常感谢各位的参与测试!

from smux.

xtaci avatar xtaci commented on August 18, 2024

https://github.com/xtaci/kcptun/releases/tag/v20190418

from smux.

xtaci avatar xtaci commented on August 18, 2024

https://github.com/xtaci/smux/releases/tag/v1.2.4

from smux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.