fix: 修复对外服重连后未向网关重新注册导致的 NPE 问题 - #544
Open
mcqwy wants to merge 1 commit into
Open
Conversation
mcqwy
commented
Aug 29, 2026
Contributor
- 问题现象:网关重启后,对外服(包括逻辑服)虽能自动恢复物理连接,但未重新执行业务注册,导致 BrokerClientManager 中无可用连接,后续请求抛出 NullPointerException(nextClient 为 null)。
- 根本原因:Bolt 的 CONN_RECONNECT_SWITCH 仅负责重连,不会触发业务注册;原代码只在启动时注册一次,缺乏重连后的注册恢复机制。
- 解决方案:
- 在 BrokerClientItem.startup() 中为 CONNECT 事件添加处理器,当物理连接建立时自动调用 tryConnect() 执行握手和注册。
- 为 CLOSE 事件添加处理器,重置连接状态并取消重试任务,确保下次 CONNECT 时能重新注册。
- 增加重试机制(DelayTaskKit),注册失败时按配置间隔重试,避免临时性故障导致服务不可用。
- 优化日志输出,所有相关日志均带上逻辑服名称(appName),便于多服务场景下快速定位。
- 影响范围:仅影响 BrokerClientItem 的行为,对外接口无变更,向后兼容。
- 测试:模拟网关重启,确认对外服自动重新注册成功,后续请求正常处理,NPE 不再出现。
- 问题现象:网关重启后,对外服虽能自动恢复物理连接,但未重新执行业务注册,导致 BrokerClientManager 中无可用连接,后续请求抛出 NullPointerException(nextClient 为 null)。 - 根本原因:Bolt 的 CONN_RECONNECT_SWITCH 仅负责重连,不会触发业务注册;原代码只在启动时注册一次,缺乏重连后的注册恢复机制。 - 解决方案: 1. 在 BrokerClientItem.startup() 中为 CONNECT 事件添加处理器,当物理连接建立时自动调用 tryConnect() 执行握手和注册。 2. 为 CLOSE 事件添加处理器,重置连接状态并取消重试任务,确保下次 CONNECT 时能重新注册。 3. 增加重试机制(DelayTaskKit),注册失败时按配置间隔重试,避免临时性故障导致服务不可用。 4. 优化日志输出,所有相关日志均带上逻辑服名称(appName),便于多服务场景下快速定位。 - 影响范围:仅影响 BrokerClientItem 的行为,对外接口无变更,向后兼容。 - 测试:模拟网关重启,确认对外服自动重新注册成功,后续请求正常处理,NPE 不再出现。
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Contributor
Author
|
抱歉可能写的部分有些误导,我发现原框架RequestBrokerClientModuleMessageClientProcessor自带重连注册机制,但依赖网关主动发送请求,可能属于被动响应式。 |
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.