-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
帧解码器这个地方的锁是否多余了 #352
Comments
@YanHeDoki 嗯,看了下代码,确实 |
func (d *FrameDecoder) failOnNegativeLengthField(in *bytes.Buffer, frameLength int64, lengthFieldEndOffset int) {
in.Next(lengthFieldEndOffset)
panic(fmt.Sprintf("negative pre-adjustment length field: %d", frameLength))
} 这个 但是上面那个lock() 应该可以直接提PR修复啦,问题不大。 |
|
@YanHeDoki 嗯,其实,就是这个问题,如果插入这个函数,来处理是否断开还是继续。 继续的话,既然decode已经失败了,那么数据流是否还可以继续解析接下来的数据。 之前的设计的目的,我理解也没有考虑这块,所以就是直接panic了,告诉当前的链接就是不可用的,但是这种确实比较暴力。 // If the data frame length is less than 0, it means it is an error data packet
// (如果数据帧长度小于0,说明是个错误的数据包)
if frameLength < 0 {
// It will skip the number of bytes of this data packet and throw an exception
// (内部会跳过这个数据包的字节数,并抛异常)
d.failOnNegativeLengthField(in, frameLength, d.LengthFieldEndOffset)
} 现在就是, |
@aceld 是的,如果直接 |
每个连接在启动的时候会构造一个解码器实例
接收到连接发的包之后是循环读取的,那么应该不会出现多线程并发调用同一个解码器的情况,这个锁是不是可以去掉
以及直接 panic 是不是太粗暴了,虽然外层 recover 了 panic 但是会直接断开连接,抛个错误在外层处理是不是好点
The text was updated successfully, but these errors were encountered: