Skip to content

Commit

Permalink
CDAP-21071 : Adding backpressure while for HttpRequestRouter using ch…
Browse files Browse the repository at this point in the history
…annelWritabilityChanged
  • Loading branch information
sahusanket committed Nov 14, 2024
1 parent 5292457 commit 3ec6b25
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,30 @@ public void channelInactive(ChannelHandlerContext ctx) {
ctx.fireChannelInactive();
}

/**
* [CDAP-21071] Handles the case by stopping the outbound channel of Service -> Router
* when the response from Service -> Router is faster than the response from Router to the Client.
*/
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
if (inflightRequests > 0 && currentMessageSender.outboundChannel != null) {
final Channel outboundChannel = ctx.channel();
ctx.executor().execute(() -> {
// If outboundChannel is not saturated anymore, continue accepting
// the incoming traffic from the outbound channel for service<>router.
if (outboundChannel.isWritable()) {
LOG.trace("Setting message sender's outboundChannel readable.");
currentMessageSender.outboundChannel.config().setAutoRead(true);
} else {
// If outboundChannel is saturated, do not read inboundChannel
LOG.trace("Setting message sender's outboundChannel non-readable.");
currentMessageSender.outboundChannel.config().setAutoRead(false);
}
});
}
ctx.fireChannelWritabilityChanged();
}

private ChannelFutureListener getFailureResponseListener(final Channel inboundChannel) {
if (failureResponseListener == null) {
failureResponseListener = new ChannelFutureListener() {
Expand Down

0 comments on commit 3ec6b25

Please sign in to comment.