Comments (23)
@xtaci 简单的测试了下,没问题了
from smux.
请提供如何重现的例子
from smux.
起初我还以为 kcp-go有bug,但是测试了几次,发现是
smux V1.2.2 V1.2.3 有问题,
from smux.
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.
对,就是这样,突然拖动视频,高清一些的,就会触发,
from smux.
之前的是ReadFull,不存在残缺数据
from smux.
@biotooff 应该不会返回0, nil的情况
from smux.
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.
我認為是cmdPSH
找不到對應的stream
然後沒有把剩餘的Frame資料讀走
接著又直接回去讀取hdr
造成錯誤(此時讀到的是cmdPSH
的資料, 而非下個Frame)
之前的實作是一定會讀取等於hdr.Length()
長度的資料
再去讀取下個Frame
from smux.
我猜的一个可能原因是receiveBytes如果存在下层阻塞,会导致Close和OpenStream阻塞的问题
from smux.
@cs8425 对的
from smux.
看来中间的buffer不可避免
from smux.
應該是可以避免中間buffer
只是要判斷如果沒有對應的stream
要記得把剩餘資料讀走&丟棄
(不只cmdPSH
, 其他cmd理論上也有可能長度不為0..?
from smux.
我認為是
cmdPSH
找不到對應的stream
然後沒有把剩餘的Frame資料讀走
接著又直接回去讀取hdr
造成錯誤(此時讀到的是cmdPSH
的資料, 而非下個Frame)
之前的實作是一定會讀取等於hdr.Length()
長度的資料
再去讀取下個Frame
确实
from smux.
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.
这样应该就ok了
from smux.
push了,各位测下
from smux.
会出现中途读取失败吗?
残余数据不一定等于datalen
from smux.
如果出现残余数据,说明链接也断开了,这个时候err会触发s.Close
from smux.
from smux.
非常感谢各位的参与测试!
from smux.
https://github.com/xtaci/kcptun/releases/tag/v20190418
from smux.
https://github.com/xtaci/smux/releases/tag/v1.2.4
from smux.
Related Issues (20)
- 修正一处细节, HOT 4
- Blocked streams under heavy load HOT 5
- smux multiplexes multiple TCP connections?
- Stream does not return net.Error for timeouts
- alloc module memory release HOT 1
- What's the difference between version1 and version2 in smux.Config? HOT 4
- cmdFIN and cmdPSH race condition HOT 2
- 如何检测一个 Conn 是否 muxing?
- proposal: add option to not close idle session HOT 1
- 一个stream不读数据,另一端stream一直写,直到缓冲满。这个时候绑定在conn上的Session将不能执行任何指令。 HOT 4
- 写超时,应用层选择重发 HOT 1
- 看了好多遍都没看懂,这个地方没有错误吗 HOT 15
- TestGetDieCh() strange behaviour seems cause by racing
- 建议增加一个 Session.GetCloseChan() 的函数,可以使用select快速得知连接已经被断开 HOT 6
- An extra character appears when using io.Copy
- 想问下协议版本1和2有什么区别 HOT 5
- 能否支持自动匹配客户端版本 (version 1,2) HOT 2
- Multiplexing over SCTP unordered mode HOT 2
- OpenStream似乎有并行性能问题
- 当并发newStream 较高时,recvLoop存在内存泄露 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smux.