Repository navigation
[Q/A][Java DUBBO RPC Triple (HTTP2)] How to close the zombi connection on the Provider side #16557
Pre-check
Apache Dubbo ComponentJava SDK (apache/dubbo) DetailsEnvironment: Dubbo 3.3.6, Triple protocol (HTTP/2) Code of Conduct
|
Replies: 1 comment 1 reply
|
In 3.3.6 only the consumer side has this.
public class IdleAwareTripleProtocol extends TripleHttp2Protocol {
@Override
public void configServerProtocolHandler(URL url, ChannelOperator operator) {
int closeTimeout = UrlUtils.getCloseTimeout(url);
super.configServerProtocolHandler(url, new ChannelOperator() {
@Override
public void configChannelHandler(List<ChannelHandler> handlers) {
List<ChannelHandler> withIdle = new ArrayList<>(handlers.size() + 1);
withIdle.add(new ChannelHandlerPretender(
new IdleStateHandler(closeTimeout, 0, 0, TimeUnit.MILLISECONDS)));
withIdle.addAll(handlers);
operator.configChannelHandler(withIdle);
}
@Override
public ProtocolDetector.Result detectResult() {
return operator.detectResult();
}
});
}
}and in Extensions under I tried it on 3.3.6 with a raw socket that sends the HTTP/2 preface and then goes quiet. Without the override the connection never gets closed. With One thing to watch: keep the provider's close timeout well above the consumers' heartbeat. The defaults (180s vs 60s) are fine, but if you set it lower than a consumer's heartbeat, idle consumers keep getting disconnected and can hit "No provider available" while they reconnect. |
In 3.3.6 only the consumer side has this.
NettyConnectionClientadds anIdleStateHandler(heartbeat, 60s by default), andTriplePingPongHandlersends an HTTP/2 PING and closes the channel if the ack doesn't come back within the close timeout. On the provider side,NettyPortUnificationServerleaves idle handling to the protocol, butTripleHttp2Protocolnever adds anIdleStateHandler, so a half-open connection just stays there.NettyServerHandleralready closes the channel when it gets anIdleStateEvent, so all that's missing is the handler. You can add it by overriding thetriwire protocol: