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

fix: read lock -> write lock #333

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Conversation

waylennn
Copy link
Collaborator

用读锁,无法避免并发写入消息,都能走入写消息的逻辑里面,导致并发写入错误

@waylennn
Copy link
Collaborator Author

ws底层会判断当前链接是否已经有消息在写入,如果有消息的同时,再次写入(并发写),会直接 panic, 这个问题是由心跳检查发现调用的sendmsg,但是sendmsg里面用的读锁,并且心跳检查是异步的,当业务里面同时调用了sendmsg ,那么就会触发ws的判断逻辑,导致报错。 这里读锁是可以并发进入逻辑执行的,所以是有问题的。

@waylennn
Copy link
Collaborator Author

sendmsgbuff 其实可以考虑不加锁实现,但是目前先加锁也没啥问题,后面可以优化,因为channel底层本身就有锁,顺带这么一提。

@aceld aceld mentioned this pull request Aug 19, 2024
@aceld
Copy link
Owner

aceld commented Aug 19, 2024

@waylennn 感谢, 针对此issue,issue#334 先进行修复,看能否复现

@aceld aceld merged commit 1b464c2 into master Aug 19, 2024
1 check passed
@pingqiang806796422
Copy link

好的,感谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants