Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ring_buffer_unix.go的问题 #288

Closed
zhu121 opened this issue Dec 6, 2021 · 3 comments
Closed

ring_buffer_unix.go的问题 #288

zhu121 opened this issue Dec 6, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@zhu121
Copy link

zhu121 commented Dec 6, 2021

Describe the bug
CopyFromSocket()函数内部在grow()后可能会把isEmpty错误的置为true,导致PeekAll()时认为是没数据的

To Reproduce
Steps to reproduce the behavior:

  1. 把MaxStreamBufferCap先改为1024byte
  2. Decode()改成需要读到1028byte才正常返回
  3. 客户端一次发送1028byte
  4. 服务端会调用两次CopyFromSocket()
  5. 第一次读到1024byte,但是数据不足
  6. 第二次读到4byte,但是调用到Reset()把isEmpty错误改为true

System Info (please complete the following information):

  • gnet version (e.g. v1.0.0): SHA-1: b8d571d
@zhu121 zhu121 added the bug Something isn't working label Dec 6, 2021
@panjf2000
Copy link
Owner

CopyFromSocket 哪有调用 Reset()?把你的代码贴出来我看下

@zhu121
Copy link
Author

zhu121 commented Dec 6, 2021

CopyFromSocket 哪有调用 Reset()?把你的代码贴出来我看下
问题在把var MaxStreamBufferCap = 64 * 1024改成var MaxStreamBufferCap = 1* 1024后,CopyFromSocket()函数里在计算rb.w时会变成是0,导致第二次调用CopyFromSocket()时调用rb.grow()->rb.Read()->rb.Reset()

以下是自定义的一个ICodec
`type testCodec struct {
}

func (cc *testCodec) Encode(c gnet.Conn, buf []byte) (out []byte, err error) {
return
}

func (cc *testCodec) Decode(c gnet.Conn) ([]byte, error) {
var buf innerBuffer
buf = c.Read()
msg, _ := buf.readN(1028)
if msg == nil {
return nil, nil
}
c.ShiftN(1028)
return msg, nil
}`

@panjf2000
Copy link
Owner

谢谢你发现这个bug。
@zhu121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants