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

Remove async from SNITcpHandle #2915

Merged
merged 8 commits into from
Oct 22, 2024
Merged

Conversation

David-Engel
Copy link
Contributor

*For easier code review, hide whitespace changes in this PR.

In our quest to remove async use on sync paths, I've refactored parallel connections in SNITcpHandle.cs. The new code leverages non-blocking sockets and Socket.Select in a single thread to connect in parallel.

To test, I created multiple semi-random entries in my local hosts file like:

127.0.0.1	test-msf
::2		test-msf
193.168.176.1	test-msf
11.13.99.44     test-msf

And used the following TCPConnectionString in config.json:
Data Source=tcp:test-msf;Database=Northwind;User=sa;Password=...;Encrypt=false;MultiSubnetFailover=true;

Here is a snippet of traces from SNITcpHandle for a failed run (invalid port: Data Source=tcp:test-msf,1444):

SNICommon.GetDnsIpAddresses | INFO | Getting DNS host entries for serverName test-msf.
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 128.0.0.1 and port 1444 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 193.168.176.1 and port 1444 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 11.13.99.44 and port 1444 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 10.12.0.1 and port 1444 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address ::2 and port 1444 using InterNetworkV6 address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Determining the status of sockets during the remaining timeout of 47710000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Failed to connect to endpoint: ::2. Error: null
SNITCPHandle.ParallelConnect | INFO | Determining the status of sockets during the remaining timeout of 47709000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Failed to connect to endpoint: 10.12.0.1. Error: null
SNITCPHandle.ParallelConnect | INFO | Determining the status of sockets during the remaining timeout of 34270000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Failed to connect to endpoint: 128.0.0.1. Error: null
SNITCPHandle.ParallelConnect | INFO | Determining the status of sockets during the remaining timeout of 26904000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Failed to connect to endpoint: 193.168.176.1. Error: null
SNITCPHandle.ParallelConnect | INFO | Determining the status of sockets during the remaining timeout of 26858000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Failed to connect to endpoint: 11.13.99.44. Error: null
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 128.0.0.1
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 193.168.176.1
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 11.13.99.44
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 10.12.0.1
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: ::2
SNITCPHandle.ParallelConnect | ERR | No connections succeeded. Last error: null

Here is a snippet of traces from SNITcpHandle for a successful run (one valid IP):

SNICommon.GetDnsIpAddresses | INFO | Getting DNS host entries for serverName test-msf.
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 193.168.176.1 and port 1433 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 11.13.99.44 and port 1433 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 10.12.0.1 and port 1433 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address 127.0.0.1 and port 1433 using InterNetwork address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Connecting to IP address ::2 and port 1433 using InterNetworkV6 address family. Is infinite timeout: False
SNITCPHandle.ParallelConnect | INFO | Watching pending sockets during the remaining timeout of 47724000 microseconds.
SNITCPHandle.ParallelConnect | INFO | Connected to endpoint: 127.0.0.1:1433
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 193.168.176.1
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 11.13.99.44
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: 10.12.0.1
SNITCPHandle.ParallelConnect | INFO | Disposing non-selected socket for endpoint: ::2

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

Attention: Patch coverage is 77.63975% with 36 lines in your changes missing coverage. Please review.

Project coverage is 71.86%. Comparing base (e006d00) to head (f6d0bc7).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...e/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs 77.63% 36 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2915   +/-   ##
=======================================
  Coverage   71.85%   71.86%           
=======================================
  Files         294      294           
  Lines       60287    60330   +43     
=======================================
+ Hits        43319    43355   +36     
- Misses      16968    16975    +7     
Flag Coverage Δ
addons 92.90% <ø> (ø)
netcore 75.82% <77.63%> (+<0.01%) ⬆️
netfx 70.35% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cheenamalhotra cheenamalhotra merged commit 1c04120 into dotnet:main Oct 22, 2024
124 checks passed
@David-Engel David-Engel deleted the parallel branch October 22, 2024 19:17
@mdaigle mdaigle added the ➕ Code Health Issues/PRs that are targeted to source code quality improvements. label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
➕ Code Health Issues/PRs that are targeted to source code quality improvements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants