fix(client): keep decode/router order without worker pool#405
Draft
ljluestc wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题现象
在客户端模式(
newCliMsgHandle)中,WorkerPoolSize被设置为0。MsgHandle.Intercept在 worker pool 关闭时使用了:go mh.doMsgHandler(...)go mh.doMsgHandlerSlices(...)上述异步分发会打破单连接消息串行语义。如果第一条消息处理较慢,后续消息可能先进入路由,从而出现“解码顺序 != 路由处理顺序”。
根因分析
无 worker pool 的处理路径在所有模式下都使用异步 goroutine 分发;但客户端业务通常期望单连接严格有序处理,二者语义不一致。
修改内容
MsgHandle增加clientMode标记:newMsgHandle()(服务端):clientMode=falsenewCliMsgHandle()(客户端):clientMode=trueMsgHandle.Intercept在无 worker pool 分支的行为:mh.doMsgHandler(...)/mh.doMsgHandlerSlices(...)go mh.doMsgHandler(...)/go mh.doMsgHandlerSlices(...)TestClientMsgHandleNoWorkerPoolPreservesOrderTestServerMsgHandleNoWorkerPoolRemainsAsync涉及文件
znet/msghandler.goznet/msghandler_client_order_test.go(新增)修复后行为
测试方式
运行定向回归测试:
go -C /home/calelin/dev/zinx test ./znet -run 'TestClientMsgHandleNoWorkerPoolPreservesOrder|TestServerMsgHandleNoWorkerPoolRemainsAsync' -count=1重复运行客户端顺序测试,验证稳定性:
go -C /home/calelin/dev/zinx test ./znet -run TestClientMsgHandleNoWorkerPoolPreservesOrder -count=10本地验证结果
定向回归测试输出:
ok github.com/aceld/zinx/znet 0.244s重复顺序测试输出:
ok github.com/aceld/zinx/znet 1.207s