Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/io/nats/client/impl/SocketDataPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ public void connect(@NonNull NatsConnection conn, @NonNull NatsUri nuri, long ti
socket = connectToFastestIp(options, host, port, (int) timeout);
} else {
socket = createSocket(options);
socket.connect(new InetSocketAddress(host, port), (int) timeout);
InetSocketAddress inetSocketAddress = (options.isNoResolveHostnames() && !nuri.hostIsIpAddress()) ?
InetSocketAddress.createUnresolved(host, port) : new InetSocketAddress(host, port);
socket.connect(inetSocketAddress, (int) timeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, resolution is supposed to be done before it gets here. Look in the NatsConnection line 540 and work backward. Also look in NatsServerPool, where it does resolveHostToIps.
Resolution does not belong here, it belongs further back up the call chain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the resolution probably belongs further back up the call chain. However the problem is that even if it didn't happen earlier, the default constructor of InetSocketAddress will perform it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be correct to say that this is only an issue in some cases AND only when a proxy is provided?

Why can't the proxy be expected to do this work?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is an issue only in some cases, it only really is an issue if a proxy is doing whitelisting based on domain names, which is a common use-case in secure/enterprise environments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the question remains, why can't this be part of the Option.proxy's responsibility? If it can be, we can simply add documentation to that effect.

I'm suspicious how common this really is in secure/enterprise environments. Enterprises are the most common users of this client, it's been around for 7 years, and this is the first time I'm hearing about the issue.

At a minimum we need an opt in solution to ensure backward compatibility, like isEnableInetAddressCreateUnresolved or something like that.

if (options.isEnableFastFallback()) {
    socket = connectToFastestIp(options, host, port, (int) timeout);
} 
else {
    InetSocketAddress inetSocketAddress;
    if (options.isEnableInetAddressUnresolved() && !nuri.hostIsIpAddress()) {
        inetSocketAddress = InetSocketAddress.createUnresolved(host, port);
    }
    else {
        inetSocketAddress = new InetSocketAddress(host, port);
    }
    socket.connect(inetSocketAddress, (int) timeout);
} 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the suggested option.

I don't understand how it could be part of the Option.proxy responsibility? What do you mean by that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proxy seems to have some flexibility. You test has a proxy implementation. It seems like code could just go in there. But at least there is a backward compatible way now, so I think that's fine.

}

if (options.getSocketReadTimeoutMillis() > 0) {
Expand Down