-
Notifications
You must be signed in to change notification settings - Fork 69
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
Conversation
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
78c4053
to
d5d08f1
Compare
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
?
Added tests for 1AddressComparer
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