You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2023/01/31 18:18:38 UTC
[pulsar] branch branch-2.11 updated (cbb17e701e7 -> aaf58319d58)
This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a change to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
from cbb17e701e7 Close TransactionBuffer when MessageDeduplication#checkStatus failed (#19289)
new 07dde2830a1 [fix][client] Prevent DNS reverse lookup when physical address is an IP address (#19028)
new aaf58319d58 [fix][client] Set fields earlier for correct ClientCnx initialization (#19327)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../admin/internal/http/AsyncHttpConnector.java | 2 +-
.../apache/pulsar/client/impl/ConnectionPool.java | 44 +++++++++++-----------
.../client/impl/PulsarChannelInitializer.java | 25 ++++++++++++
.../client/impl/PulsarServiceNameResolver.java | 2 +-
4 files changed, 48 insertions(+), 25 deletions(-)
[pulsar] 02/02: [fix][client] Set fields earlier for correct ClientCnx initialization (#19327)
Posted by mm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit aaf58319d58a1a586f2d2853bfca2bed8f3cd66a
Author: Michael Marshall <mm...@apache.org>
AuthorDate: Mon Jan 30 03:29:52 2023 -0600
[fix][client] Set fields earlier for correct ClientCnx initialization (#19327)
(cherry picked from commit 3d8b52a9531185f3b273bc10dda07243abb30862)
---
.../apache/pulsar/client/impl/ConnectionPool.java | 44 +++++++++++-----------
.../client/impl/PulsarChannelInitializer.java | 25 ++++++++++++
2 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
index 789e1f48ff9..cde667b0a44 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
@@ -244,7 +244,7 @@ public class ConnectionPool implements AutoCloseable {
final CompletableFuture<ClientCnx> cnxFuture = new CompletableFuture<>();
// Trigger async connect to broker
- createConnection(physicalAddress).thenAccept(channel -> {
+ createConnection(logicalAddress, physicalAddress).thenAccept(channel -> {
log.info("[{}] Connected to server", channel);
channel.closeFuture().addListener(v -> {
@@ -266,16 +266,6 @@ public class ConnectionPool implements AutoCloseable {
return;
}
- if (!logicalAddress.equals(physicalAddress)) {
- // We are connecting through a proxy. We need to set the target broker in the ClientCnx object so that
- // it can be specified when sending the CommandConnect.
- // That phase will happen in the ClientCnx.connectionActive() which will be invoked immediately after
- // this method.
- cnx.setTargetBroker(logicalAddress);
- }
-
- cnx.setRemoteHostName(physicalAddress.getHostString());
-
cnx.connectionFuture().thenRun(() -> {
if (log.isDebugEnabled()) {
log.debug("[{}] Connection handshake completed", cnx.channel());
@@ -303,7 +293,8 @@ public class ConnectionPool implements AutoCloseable {
/**
* Resolve DNS asynchronously and attempt to connect to any IP address returned by DNS server.
*/
- private CompletableFuture<Channel> createConnection(InetSocketAddress unresolvedAddress) {
+ private CompletableFuture<Channel> createConnection(InetSocketAddress logicalAddress,
+ InetSocketAddress unresolvedPhysicalAddress) {
CompletableFuture<List<InetSocketAddress>> resolvedAddress;
try {
if (isSniProxy) {
@@ -311,11 +302,11 @@ public class ConnectionPool implements AutoCloseable {
resolvedAddress =
resolveName(InetSocketAddress.createUnresolved(proxyURI.getHost(), proxyURI.getPort()));
} else {
- resolvedAddress = resolveName(unresolvedAddress);
+ resolvedAddress = resolveName(unresolvedPhysicalAddress);
}
return resolvedAddress.thenCompose(
- inetAddresses -> connectToResolvedAddresses(inetAddresses.iterator(),
- isSniProxy ? unresolvedAddress : null));
+ inetAddresses -> connectToResolvedAddresses(logicalAddress, inetAddresses.iterator(),
+ isSniProxy ? unresolvedPhysicalAddress : null));
} catch (URISyntaxException e) {
log.error("Invalid Proxy url {}", clientConfig.getProxyServiceUrl(), e);
return FutureUtil
@@ -327,17 +318,19 @@ public class ConnectionPool implements AutoCloseable {
* Try to connect to a sequence of IP addresses until a successful connection can be made, or fail if no
* address is working.
*/
- private CompletableFuture<Channel> connectToResolvedAddresses(Iterator<InetSocketAddress> unresolvedAddresses,
+ private CompletableFuture<Channel> connectToResolvedAddresses(InetSocketAddress logicalAddress,
+ Iterator<InetSocketAddress> resolvedPhysicalAddress,
InetSocketAddress sniHost) {
CompletableFuture<Channel> future = new CompletableFuture<>();
// Successfully connected to server
- connectToAddress(unresolvedAddresses.next(), sniHost)
+ connectToAddress(logicalAddress, resolvedPhysicalAddress.next(), sniHost)
.thenAccept(future::complete)
.exceptionally(exception -> {
- if (unresolvedAddresses.hasNext()) {
+ if (resolvedPhysicalAddress.hasNext()) {
// Try next IP address
- connectToResolvedAddresses(unresolvedAddresses, sniHost).thenAccept(future::complete)
+ connectToResolvedAddresses(logicalAddress, resolvedPhysicalAddress, sniHost)
+ .thenAccept(future::complete)
.exceptionally(ex -> {
// This is already unwinding the recursive call
future.completeExceptionally(ex);
@@ -368,17 +361,22 @@ public class ConnectionPool implements AutoCloseable {
/**
* Attempt to establish a TCP connection to an already resolved single IP address.
*/
- private CompletableFuture<Channel> connectToAddress(InetSocketAddress remoteAddress, InetSocketAddress sniHost) {
+ private CompletableFuture<Channel> connectToAddress(InetSocketAddress logicalAddress,
+ InetSocketAddress physicalAddress, InetSocketAddress sniHost) {
if (clientConfig.isUseTls()) {
return toCompletableFuture(bootstrap.register())
.thenCompose(channel -> channelInitializerHandler
- .initTls(channel, sniHost != null ? sniHost : remoteAddress))
+ .initTls(channel, sniHost != null ? sniHost : physicalAddress))
.thenCompose(channelInitializerHandler::initSocks5IfConfig)
- .thenCompose(channel -> toCompletableFuture(channel.connect(remoteAddress)));
+ .thenCompose(ch ->
+ channelInitializerHandler.initializeClientCnx(ch, logicalAddress, physicalAddress))
+ .thenCompose(channel -> toCompletableFuture(channel.connect(physicalAddress)));
} else {
return toCompletableFuture(bootstrap.register())
.thenCompose(channelInitializerHandler::initSocks5IfConfig)
- .thenCompose(channel -> toCompletableFuture(channel.connect(remoteAddress)));
+ .thenCompose(ch ->
+ channelInitializerHandler.initializeClientCnx(ch, logicalAddress, physicalAddress))
+ .thenCompose(channel -> toCompletableFuture(channel.connect(physicalAddress)));
}
}
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarChannelInitializer.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarChannelInitializer.java
index b046d1030ed..f8f61f05661 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarChannelInitializer.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarChannelInitializer.java
@@ -43,6 +43,7 @@ import org.apache.pulsar.common.protocol.ByteBufPair;
import org.apache.pulsar.common.protocol.Commands;
import org.apache.pulsar.common.util.SecurityUtility;
import org.apache.pulsar.common.util.keystoretls.NettySSLContextAutoRefreshBuilder;
+import org.apache.pulsar.common.util.netty.NettyFutureUtil;
@Slf4j
public class PulsarChannelInitializer extends ChannelInitializer<SocketChannel> {
@@ -209,5 +210,29 @@ public class PulsarChannelInitializer extends ChannelInitializer<SocketChannel>
return initSocks5Future;
}
+
+ CompletableFuture<Channel> initializeClientCnx(Channel ch,
+ InetSocketAddress logicalAddress,
+ InetSocketAddress resolvedPhysicalAddress) {
+ return NettyFutureUtil.toCompletableFuture(ch.eventLoop().submit(() -> {
+ final ClientCnx cnx = (ClientCnx) ch.pipeline().get("handler");
+
+ if (cnx == null) {
+ throw new IllegalStateException("Missing ClientCnx. This should not happen.");
+ }
+
+ // Need to do our own equality because the physical address is resolved already
+ if (!(logicalAddress.getHostString().equalsIgnoreCase(resolvedPhysicalAddress.getHostString())
+ && logicalAddress.getPort() == resolvedPhysicalAddress.getPort())) {
+ // We are connecting through a proxy. We need to set the target broker in the ClientCnx object so that
+ // it can be specified when sending the CommandConnect.
+ cnx.setTargetBroker(logicalAddress);
+ }
+
+ cnx.setRemoteHostName(resolvedPhysicalAddress.getHostString());
+
+ return ch;
+ }));
+ }
}
[pulsar] 01/02: [fix][client] Prevent DNS reverse lookup when physical address is an IP address (#19028)
Posted by mm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
mmarshall pushed a commit to branch branch-2.11
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 07dde2830a1147d80349e181da6057f21f28d9b9
Author: Lari Hotari <lh...@users.noreply.github.com>
AuthorDate: Fri Dec 23 16:32:34 2022 +0200
[fix][client] Prevent DNS reverse lookup when physical address is an IP address (#19028)
(cherry picked from commit d8569cd4ec6da14f8b2b9338db1ed2f6a3eacf0a)
---
.../apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java | 2 +-
.../src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java | 2 +-
.../java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java
index ea00930e546..9ce7bb82af7 100644
--- a/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java
+++ b/pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/http/AsyncHttpConnector.java
@@ -210,7 +210,7 @@ public class AsyncHttpConnector implements Connector {
private URI replaceWithNew(InetSocketAddress address, URI uri) {
String originalUri = uri.toString();
String newUri = (originalUri.split(":")[0] + "://")
- + address.getHostName() + ":"
+ + address.getHostString() + ":"
+ address.getPort()
+ uri.getRawPath();
if (uri.getRawQuery() != null) {
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
index 36f28fb5756..789e1f48ff9 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConnectionPool.java
@@ -274,7 +274,7 @@ public class ConnectionPool implements AutoCloseable {
cnx.setTargetBroker(logicalAddress);
}
- cnx.setRemoteHostName(physicalAddress.getHostName());
+ cnx.setRemoteHostName(physicalAddress.getHostString());
cnx.connectionFuture().thenRun(() -> {
if (log.isDebugEnabled()) {
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java
index c7db56adc4b..1b90f25d926 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarServiceNameResolver.java
@@ -61,7 +61,7 @@ public class PulsarServiceNameResolver implements ServiceNameResolver {
@Override
public URI resolveHostUri() {
InetSocketAddress host = resolveHost();
- String hostUrl = serviceUri.getServiceScheme() + "://" + host.getHostName() + ":" + host.getPort();
+ String hostUrl = serviceUri.getServiceScheme() + "://" + host.getHostString() + ":" + host.getPort();
return URI.create(hostUrl);
}