runtime icon indicating copy to clipboard operation
runtime copied to clipboard

SqlClient / MultiSubnetFailover / Linux / 1.1.0

Open jamesgibbs100 opened this issue 9 years ago • 49 comments

I would really appreciate some advice if possible.

I'm running a .NET Core App 1.1.0 in a container against a SqlServer 12 database with MultiSubnetFailover.

My connection string looks like this...

Data Source=..***.com;Initial Catalog=DATABASENAME;User ID=USER_ID;Password="USER_PASSWORD";Connect Timeout=60;TrustServerCertificate=True;Application Name=".NET Core";MultiSubnetFailover=True

There are just two subnets, so when I resolved the dns name I get 2 ip addresses back. As long as the primary is listed first, I can connect. If the secondary is listed first it will timeout and fail

Does this mean that MSF is not available in Linux ?? Have I got an incorrect ConnectionString ? Is the IP resolution running in serial and not parallel ?

I've tried all manner of things - for example - setting the connection time out to 200 (based on some similar queries). I've also read that I should not specify the Initial Catalog (on linux) when using MSF but this is an onerous solution to me.

Would appreciate some advice on this one as I'm running out of options and want to go into production....

Thanks in advance James

jamesgibbs100 avatar Jan 08 '17 20:01 jamesgibbs100

Quick update. A simple client running on linux. (.NET Core 1.1.0 / System.Data.SqlClient 4.3) fails when DNS resolves the the secondary first.

Failure (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server))

It works fine on Windows with either the primary or secondary presented first from DNS.

Is anyone able to confirm (or not) that MSF works on Linux as well as Windows ?

Thanks James

jamesgibbs100 avatar Jan 09 '17 14:01 jamesgibbs100

@saurabh500 can you help please?

karelz avatar Jan 10 '17 00:01 karelz

@corivera, can you help with this issue with MSF in Managed SNI?

saurabh500 avatar Jan 10 '17 00:01 saurabh500

@corivera @saurabh500 Sorry to nudge on this but time is short - is there any workaround/advice you can provide me ?

jamesgibbs100 avatar Jan 11 '17 16:01 jamesgibbs100

@jamesgibbs100 Right now we don't know what is going on. @corivera is looking into this issue. What Linux flavor are you using?

saurabh500 avatar Jan 11 '17 19:01 saurabh500

I was able to repro the issue locally. Looking into it.

corivera avatar Jan 11 '17 20:01 corivera

@saurabh500 @corivera : Thank you gentlemen. I'm online and will be for a few hours, so if you need me to provide more info / test or clarify - please reach out.

jamesgibbs100 avatar Jan 11 '17 20:01 jamesgibbs100

FYI : I can produce this in two environment -

Firstly, a Rancher powered container environment running on a base docker image FROM microsoft/dotnet:1.1.0-runtime

Secondly, on a VirtualBox run image as below :

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.5 LTS Release: 14.04 Codename: trusty

Linux new-linux-box 3.13.0-96-generic dotnet/corefx#143-Ubuntu SMP Mon Aug 29 20:15:20 UTC 2016 x86_64 x86_64

jamesgibbs100 avatar Jan 11 '17 20:01 jamesgibbs100

FYI : Recently, the connection was encrypted - hence the TrustServerCertificate=True. It is possible its in this area - although this is nothing more than a hunch. I had not noticed any issue prior to that but then again I cannot say for certain if I just wasnt getting the primary IP address all the time - maybe a redherring - just sharing

jamesgibbs100 avatar Jan 11 '17 20:01 jamesgibbs100

@jamesgibbs100 TrustServerCertificate is only relevant when Encrypt=true. Interestingly, when I increase my timeout from 15 seconds to 60 I start seeing successes, although it takes most of that time to get the query results back. Can you try increasing your timeout to maybe 120 to see if that returns some success?

corivera avatar Jan 11 '17 21:01 corivera

I will try again - but having read the documentation on how the time out is sliced when MSF is involved I have previously tried 200. I will try again though

jamesgibbs100 avatar Jan 11 '17 21:01 jamesgibbs100

No joy I'm afraid

Primary returned first from DNS and the world is good :

Resolve (132ms) XXXXXX.com to 10.XXX.49.53,10.XXX.48.53 0 1969 Success 1 5 Success 2 0 Success

Secondary returned first from DNS

Resolve (8ms) XXXXXX.com to 10.XXX.48.53,10.XXX.49.53 0 200049 Failure [XXXXXX.com] (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)) 1 7 Failure [XXXXXX.com] (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)) 2 0 Failure [XXXXXX.com] (A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Ve

[First number is index, second the time taken in ms - you can see the 200 timeout occuring]

jamesgibbs100 avatar Jan 11 '17 21:01 jamesgibbs100

FYI : The DNS resolution is nothing more than

Task<IPAddress[]> ipAddressesTask = Dns.GetHostAddressesAsync(host);

I assume the order stays consistent when the call enters the internals of SqlConnection.Open()

jamesgibbs100 avatar Jan 11 '17 21:01 jamesgibbs100

Do you notice any difference when including the port number in the data source? e.g. try using Data Source=tcp:SERVER,PORT

corivera avatar Jan 11 '17 23:01 corivera

@corivera : I've not tried.

I will try 1433 just now - bear with me

jamesgibbs100 avatar Jan 11 '17 23:01 jamesgibbs100

Yes.

When primary reported first from DNS

Resolve (7ms) XXXXXX.com,1433 to 10.XXX.49.53,10.XXX.48.53 0 17049 Success 1 11 Success 2 0 Success

[Longer time on initial success]

When secondary frist reported from DNS

Resolve (7ms) XXXXXX.com,1433 to 10.XXX.48.53,10.XXX.49.53 0 977 Success 1 11 Success 2 0 Success

This is the first success I've had given a secondary DNS ipAddress.

ConnsectionString = "Data Source=XXXXXX.com,1433;Initial Catalog=DATABASE;User ID=USER_ID;Password="PASSWORD";Connect Timeout=200;TrustServerCertificate=True;Application Name=".NET Core";MultiSubnetFailover=True;";

jamesgibbs100 avatar Jan 11 '17 23:01 jamesgibbs100

Running multiple times with SERVER,PORT results in expected/hoped for performance - smiling

Oddly, now DNS always returns the same ipAddress order, where as before it would alternate ??!??

jamesgibbs100 avatar Jan 11 '17 23:01 jamesgibbs100

We have a bug where connections eat up a lot of time when no port is specified, since we try to do some queries to get the port in case the server is using dynamic ports. That might be what's causing this issue.

corivera avatar Jan 11 '17 23:01 corivera

The issue is being tracked by dotnet/corefx#15089

saurabh500 avatar Jan 11 '17 23:01 saurabh500

hey - bugs happen :-)

You are obviously onto it

Is my expectation right for the below :

a) Include the port (however I do this) and the problem goes away b) "It" will be resolved quickly - (I cannot imagine the Sql team wanting this hanging around ?)

Basically, I didnt want to put the work around in place that I had been planning - I am comfortable if including the port number sidesteps the problem and that I know there is resolution insight

jamesgibbs100 avatar Jan 11 '17 23:01 jamesgibbs100