Fix RPC hang on abrupt connection disconnect.#438
Merged
Conversation
3685cd0 to
8867c32
Compare
WeiXinChan
reviewed
Jun 24, 2026
| } | ||
|
|
||
| @Override | ||
| public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
Contributor
There was a problem hiding this comment.
缩进为 2 空格,项目其他文件多为 4 空格,风格不一致
Notify pending invoke futures when the channel becomes inactive and return BOLT_SEND_FAILED for connection-closed responses, so in-flight requests fail immediately instead of waiting for RPC timeout. Skip suspect-server tracking when ObServerAddr is unset to avoid NPE in direct load reconnect paths.
8867c32 to
d6a3457
Compare
Contributor
|
LGTM |
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.
Notify pending invoke futures when the channel becomes inactive and return BOLT_SEND_FAILED for connection-closed responses, so in-flight requests fail immediately instead of waiting for RPC timeout. Skip suspect-server tracking when ObServerAddr is unset to avoid NPE in direct load reconnect paths.
Summary
Fix the issue where in-flight RPC requests hang until RPC timeout when the underlying connection is abruptly closed (network failure, server crash, etc.). Pending requests should fail immediately with a transport error instead of waiting for the timeout timer.
Solution Description
Root cause: When a connection drops unexpectedly, Netty only triggers channelInactive and does not go through Connection.close(). Bolt’s Connection.onClose() (which completes pending InvokeFutures) was therefore not called. Additionally, ObClientFuture and ObPacketFactory returned null from createConnectionClosedResponse, so BaseRemoting.invokeSync treated the result as a timeout (BOLT_TIMEOUT) rather than a connection-closed error.
Changes:
ObConnectionEventHandler — On channelInactive, call connection.onClose() so all pending invoke futures are completed immediately when the channel goes inactive.
ObClientFuture / ObPacketFactory — Implement createConnectionClosedResponse to return a transport error packet with BOLT_SEND_FAILED and message connection {addr} closed, instead of null.
ObTable — Use ObConnectionEventHandler instead of the default ConnectionEventHandler.
Direct load reconnect NPE — Skip RouteTableRefresher.addIntoSuspectIPs when ObServerAddr is unset (direct load does not use route refresh). Add a null guard in addIntoSuspectIPs as a safety net.
Expected behavior after fix: On disconnect, in-flight RPC fails within seconds with ObTableTransportException (transportCode: -20003, connection closed), not after RPC timeout (-20002). If reconnect succeeds on the next request, execution continues normally without throwing an exception.