diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 402e1e3319..60e932c9f3 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -23,13 +23,13 @@ path = "../native/build/libs/http-native-2.10.0-SNAPSHOT.jar" groupId = "io.ballerina.stdlib" artifactId = "mime-native" version = "2.9.0" -path = "./lib/mime-native-2.9.0-20230831-160900-6ecc648.jar" +path = "./lib/mime-native-2.9.0-20230911-153200-3add04c.jar" [[platform.java17.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" version = "1.4.0" -path = "./lib/constraint-native-1.4.0-20230831-142400-50e4023.jar" +path = "./lib/constraint-native-1.4.0-20230911-142700-8202202.jar" [[platform.java17.dependency]] groupId = "io.netty" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0768a2172b..3f4aa0b0d6 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.0-20230830-220400-8a7556d8" +distribution-version = "2201.8.0-20230908-135700-74a59dff" [[package]] org = "ballerina" diff --git a/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/DefaultHttpClientConnector.java b/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/DefaultHttpClientConnector.java index 5d233d1a1b..1358a8774a 100644 --- a/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/DefaultHttpClientConnector.java +++ b/native/src/main/java/io/ballerina/stdlib/http/transport/contractimpl/DefaultHttpClientConnector.java @@ -211,22 +211,13 @@ public void onSuccess(String protocol, ChannelFuture channelFuture) { route.toString() + " " + "Original Channel ID is : " + channelFuture.channel().id()); } - if (Constants.HTTP_SCHEME.equalsIgnoreCase(protocol) && http1xSrcHandler != null) { - channelFuture.channel().deregister().addListener(future -> - http1xSrcHandler.getEventLoop() - .register(channelFuture.channel()) - .addListener( - future1 -> - startExecutingOutboundRequest( - protocol, channelFuture))); - } else if (Constants.HTTP_SCHEME.equalsIgnoreCase(protocol) && http2SrcHandler != null) { - channelFuture.channel().deregister().addListener(future -> - http2SrcHandler.getChannelHandlerContext() - .channel().eventLoop() - .register(channelFuture.channel()) - .addListener(future1 -> - startExecutingOutboundRequest( - protocol, channelFuture))); + if (isH1c(protocol)) { + switchEventLoopForH1c(channelFuture).addListener(future -> + startExecutingOutboundRequest(protocol, channelFuture)); + + } else if (isH2c(protocol)) { + switchEventLoopForH2c(channelFuture).addListener(future -> + startExecutingOutboundRequest(protocol, channelFuture)); } else { startExecutingOutboundRequest(protocol, channelFuture); } @@ -299,6 +290,27 @@ private void initializeSenderReqRespStateMgr(Channel targetNettyChannel) { targetChannel.senderReqRespStateManager = senderReqRespStateManager; } + // Switching is done to make sure, inbound request/response and the outbound request/response + // are handle on the same thread and thereby avoid the need for locks + private ChannelFuture switchEventLoopForH1c(ChannelFuture channelFuture) { + return channelFuture.channel().deregister() + .addListener(future -> http1xSrcHandler.getEventLoop().register(channelFuture.channel())); + } + + private ChannelFuture switchEventLoopForH2c(ChannelFuture channelFuture) { + return channelFuture.channel().deregister().addListener(future -> + http2SrcHandler.getChannelHandlerContext().channel().eventLoop() + .register(channelFuture.channel())); + } + + private boolean isH1c(String protocol) { + return Constants.HTTP_SCHEME.equalsIgnoreCase(protocol) && http1xSrcHandler != null; + } + + private boolean isH2c(String protocol) { + return Constants.HTTP_SCHEME.equalsIgnoreCase(protocol) && http2SrcHandler != null; + } + @Override public void onFailure(ClientConnectorException cause) { httpResponseFuture.notifyHttpListener(cause);