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

Add IP address preference support for TCP connection #1015

Merged
merged 29 commits into from
May 17, 2021
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
612f259
Add IPAddressPreference net core
karinazhou Mar 24, 2021
2314a55
Merge branch 'main' of https://github.com/dotnet/SqlClient into IPAdd…
karinazhou Mar 24, 2021
b5c42ff
netcore SynonymCount update
karinazhou Mar 25, 2021
5ca9b4a
Add keyword in netfx
karinazhou Mar 26, 2021
444ab9b
Add IP preference logic
karinazhou Mar 31, 2021
ce608d3
Fix incorrect description
karinazhou Apr 1, 2021
673dc39
Apply suggestions from code review
karinazhou Apr 8, 2021
1f27eb7
Update DNS cache descripption
karinazhou Apr 8, 2021
5d42d26
Merge branch 'IPAddressPreference' of https://github.com/karinazhou/S…
karinazhou Apr 8, 2021
63d07bc
Merge remote-tracking branch 'upstream/main' into pr/1015
johnnypham Apr 16, 2021
37a0b77
tests for ip address preference
johnnypham Apr 19, 2021
0b6c0e4
Update SNITcpHandle.cs
johnnypham Apr 19, 2021
8fa43b8
Update ConfigurableIpPreferenceTest.cs
johnnypham Apr 23, 2021
dfeea18
Update src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlCli…
johnnypham Apr 23, 2021
b5a625b
Improvement
Apr 30, 2021
0cf2304
Merge remote-tracking branch 'UpStream/main' into IPAddressPreference
Apr 30, 2021
5642e74
Add new configurations
Apr 30, 2021
e8b3ca4
Revert "Add new configurations"
Apr 30, 2021
ac69f38
Update default config
Apr 30, 2021
16935d4
Add test
May 6, 2021
ee3dbd3
Merge remote-tracking branch 'UpStream/main' into IPAddressPreference
May 11, 2021
4a1d7f7
Apply suggestions from code review
DavoudEshtehari May 11, 2021
c71143c
Address comments
May 11, 2021
8464adb
Apply suggestions from code review
DavoudEshtehari May 11, 2021
ebbc42b
Address comments
May 13, 2021
12ff426
Apply suggestions from code review
DavoudEshtehari May 13, 2021
a2bc385
Address comments
May 13, 2021
0f27fde
Update doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPr…
DavoudEshtehari May 14, 2021
019fce0
Address comments
May 14, 2021
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into pr/1015
johnnypham committed Apr 16, 2021

Unverified

This user has not yet uploaded their public signing key.
commit 63d07bce7d22844c435e6a9a3b84457fac0e96bb
Original file line number Diff line number Diff line change
@@ -339,9 +339,6 @@ private static Socket Connect(string serverName, int port, TimeSpan timeout, boo
string IPv4String = null;
string IPv6String = null;

Socket[] sockets = new Socket[2];
AddressFamily[] preferedIPFamilies = new AddressFamily[2];

if (ipPreference == SqlConnectionIPAddressPreference.IPv6First)
{
preferedIPFamilies[0] = AddressFamily.InterNetworkV6;
@@ -352,6 +349,14 @@ private static Socket Connect(string serverName, int port, TimeSpan timeout, boo
preferedIPFamilies[0] = AddressFamily.InterNetwork;
preferedIPFamilies[1] = AddressFamily.InterNetworkV6;
}
// Returning null socket is handled by the caller function.
if(ipAddresses == null || ipAddresses.Length == 0)
johnnypham marked this conversation as resolved.
Show resolved Hide resolved
{
return null;
}

Socket[] sockets = new Socket[ipAddresses.Length];
AddressFamily[] preferedIPFamilies = new AddressFamily[] { AddressFamily.InterNetwork, AddressFamily.InterNetworkV6 };

CancellationTokenSource cts = null;

@@ -383,13 +388,14 @@ void Cancel()
Socket availableSocket = null;
try
{
int n = 0; // Socket index

// We go through the IP list twice.
// In the first traversal, we only try to connect with the preferedIPFamilies[0].
// In the second traversal, we only try to connect with the preferedIPFamilies[1].
// For UsePlatformDefault preference, we do traveral once.
for (int i = 0; i < preferedIPFamilies.Length; ++i)
{

foreach (IPAddress ipAddress in ipAddresses)
{
try
@@ -401,18 +407,18 @@ void Cancel()
continue;
}

JRahnama marked this conversation as resolved.
Show resolved Hide resolved
sockets[i] = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
sockets[n] = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

// enable keep-alive on socket
SetKeepAliveValues(ref sockets[i]);
SetKeepAliveValues(ref sockets[n]);

SqlClientEventSource.Log.TrySNITraceEvent(s_className, EventType.INFO, "Connecting to IP address {0} and port {1}", args0: ipAddress, args1: port);
sockets[i].Connect(ipAddress, port);
if (sockets[i] != null) // sockets[i] can be null if cancel callback is executed during connect()
sockets[n].Connect(ipAddress, port);
if (sockets[n] != null) // sockets[n] can be null if cancel callback is executed during connect()
{
if (sockets[i].Connected)
if (sockets[n].Connected)
{
availableSocket = sockets[i];
availableSocket = sockets[n];
if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
{
IPv4String = ipAddress.ToString();
@@ -421,12 +427,13 @@ void Cancel()
{
IPv6String = ipAddress.ToString();
}

break;
}
else
{
sockets[i].Dispose();
sockets[i] = null;
sockets[n].Dispose();
sockets[n] = null;
}
}
n++;
You are viewing a condensed version of this merge commit. You can view the full changes here.