feat(rpc): 新增虚拟线程友好的同步阻塞调用 invokeSync - #109
Open
Gu-ZT wants to merge 2 commits into
Open
Conversation
Gu-ZT
commented
Aug 24, 2026
Contributor
- 新增 RPC.invokeSync 系列(0~16 参 + invokeSyncByName),在(虚拟)线程内阻塞等待对端响应,直接返回结果
- 复用既有 RpcPendingCalls 登记与超时机制,不引入额外线程池或依赖
- 保持原有 CompletableFuture invoke 形态不变,回调继续走 ForkJoinPool.commonPool / 调用方显式 executor
- module.test 新增 /rpctest invoke-sync 命令,在虚拟线程中验证同步调用
- 新增 invokeSync(target, allowNonVirtual, ref, args...) 0~16 参全部重载,由调用方显式声明是否允许在非虚拟线程阻塞
- 全部 allowNonVirtual 重载标注 @ApiStatus.Experimental,与原有默认警告版本共存
- 新增 RPC.invokeSync 系列(0~16 参 + invokeSyncByName),在(虚拟)线程内阻塞等待对端响应,直接返回结果 - 复用既有 RpcPendingCalls 登记与超时机制,不引入额外线程池或依赖 - 保持原有 CompletableFuture invoke 形态不变,回调继续走 ForkJoinPool.commonPool / 调用方显式 executor - module.test 新增 /rpctest invoke-sync 命令,在虚拟线程中验证同步调用
- 新增 invokeSync(target, allowNonVirtual, ref, args...) 0~16 参全部重载,由调用方显式声明是否允许在非虚拟线程阻塞 - 全部 allowNonVirtual 重载标注 @ApiStatus.Experimental,与原有默认警告版本共存 - 移除 AllowSync 远端方法注解方案,将阻塞决策权归还调用方 - 私有 invokeSyncChecked 增加 allowNonVirtual 参数,非虚拟线程仅警告不阻断
|
分析完成。所有声称均已交叉验证。输出审查意见: 代码审查摘要 — PR #109操作: opened 🔴 关键
|
| 声称 | 状态 | 对应证据 |
|---|---|---|
| invokeSync 0~16 参全重载 | ✅ | 17 个 arity,总计 34 个重载 |
| invokeSyncByName 逃生口 | ✅ | 与 invokeByName 对称,走同一 invokeSyncChecked |
| allowNonVirtual 重载全部 @ApiStatus.Experimental | ✅ | 17 处标注,恰为 0~16 的 experimental 变体 |
| 复用 RpcPendingCalls 登记与超时,无新线程池 | ✅ | 无新增依赖/线程池,超时/断线异常路径完整 |
| 原有 CompletableFuture invoke 形态不变 | ✅ | diff 仅新增,无删改 |
module.test /rpctest invoke-sync |
✅ | 已注册命令并接入 runAllTests 调度(tick 40) |
结论: REQUEST_CHANGES — 功能实现本身质量高、与既有架构一致,唯一阻塞项是 allowNonVirtual javadoc 将 Netty 线程列为可阻塞线程与实现直接矛盾(一行文档修改即可);建议同时补充 invokeSyncByName 的 experimental 变体与异常语义说明。
🧪 测试建议
| 被测目标 | 推荐测试场景 | 优先级 |
|---|---|---|
RPC.invokeSyncChecked |
超时路径:对端不响应 → 验证 join() 抛 CompletionException(TimeoutException),且调用方可捕获 | 🔴 |
RPC.invokeSyncChecked |
断线路径:调用后断开连接 → CompletionException(CancellationException) | 🟡 |
RPC.invokeSync(target, ..., true) |
主线程调用(allowNonVirtual=true)+ 响应丢失 → 验证当前文档化死锁行为的日志告警 | 🟡 |
RPC.invokeSync F0~F16 |
每 arity 至少一次往返(现测试仅覆盖 F0/F1/F2/F3 等价路径) | 🟢 |
由 Hermes Agent 审查
🌿 Roseau API Breaking Change Report
|
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.