Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve dns to ip addresses when establishing socket connection #167

Merged
merged 3 commits into from
Apr 20, 2017

Conversation

zhenlineo
Copy link
Contributor

When establish a socket connection, instead of using (Uri.Host, Uri.Port), we will use (IPAddress, port) instead to avoid issues on some platform where socket cannot be established with dns addresses due to one to many mapping.

If the uri given is already an ip address, then the ip address will be used directly. Otherwise, we will perform a dns lookup to resolve to ip addresses. The resolved ip addresses will be put in an array where IPv6 addresses will be placed first. Then socket client will try to establish connections with the server's ip addresses in order until connection established successfully.

This change does not implement connection pool level dns resolution. The connection pool still holds a pool for each uri (could either be a dns or ip address). While this PR does not need to be modified when connection pool level dns lookup is added as the socket client will not do a dns resolve if the uri is already an ip address.

Fix for #164
Based on #166

Zhen Li added 2 commits April 12, 2017 14:05
When establish a socket connection, instead of using `(Uri.Host, Uri.Port)`, we will use `(IPAddress, port)` instead to avoid issues on some platform where socket cannot be established with dns addresses due to one to many mapping.

If the uri given is already an ip address, then the ip address will be used directly. Otherwise, we will perform a dns lookup to resolve to ip addresses. The resolved ip addresses will be put in an array where IPv6 addresses will be placed first. Then socket client will try to establish connections with the server's ip addresses in order until connection established successfully.

This change does not implement connection pool level dns resolution. The connection pool still holds a pool for each uri (could either be a dns or ip address). While this PR does not need to be modified when connection pool level dns lookup is added as the socket client will not do a dns resolve if the uri is already an ip address.

Fix for neo4j#164
@zhenlineo zhenlineo changed the base branch from 1.3 to 1.2 April 13, 2017 14:08
Copy link
Contributor

@lutovich lutovich left a comment

Choose a reason for hiding this comment

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

@zhenlineo looks good, two small comments.

@@ -73,6 +72,26 @@ public TcpSocketClient(EncryptionManager encryptionManager, bool keepAlive, ILog
}
}

private async Task Connect(Uri uri)
{
var addresses = await uri.ResolveAsyc();
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably log these addresses in debug mode and include them in the IOException

return addresses;
}

private class AddressComparer : IComparer<IPAddress>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add some unit tests for AddressComparer?

@zhenlineo zhenlineo merged commit 7dd3231 into neo4j:1.2 Apr 20, 2017
@zhenlineo zhenlineo deleted the 1.2-dns-resolve branch April 20, 2017 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants