Bug #97872 'keepalive' in connection string throws exception on .Net Core
Submitted: 4 Dec 2019 1:19 Modified: 4 Dec 2019 11:10
Reporter: Mark Rutherford Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.18, 8.0.31 OS:Linux
Assigned to: CPU Architecture:Any
Tags: .Net Core

[4 Dec 2019 1:19] Mark Rutherford
Use of 'keepalive' in the connection string on .Net Core should probably be a warning. 

Snippet of exception:

2019-12-04 00:34:26.4821|1|ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An unhandled exception has occurred while executing the request. MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
 ---> System.PlatformNotSupportedException: Socket.IOControl handles Windows-specific control codes and is not supported on this platform.
   at System.Net.Sockets.SocketPal.WindowsIoctl(SafeSocketHandle handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)
   at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
   at System.Net.Sockets.Socket.IOControl(IOControlCode ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
   at MySql.Data.Common.StreamCreator.SetKeepAlive(Socket s, UInt32 time)
   at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.NativeDriver.Open()
   at MySql.Data.MySqlClient.Driver.Open()
   at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPool..ctor(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlPoolManager.GetPool(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.MySqlConnection.Open()

How to repeat:
add something like 'keepalive=60;' to your connection string in a .net core application and try to run it on a Linux system.

Suggested fix:
This should probably either be ignored on .net core or a warning issued.
Otherwise, the workaround is to remove keepalive from the connection string.
[4 Dec 2019 11:10] MySQL Verification Team
Hello Mark Rutherford,

Thank you for the report.

[5 Dec 2019 3:47] Bradley Grainger
Connector/NET should use the new SocketOptionName.TcpKeepAlive* options that were introduced in .NET Core 3.0: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socketoptionname?view=netco...

See also https://github.com/dotnet/corefx/issues/25040.
[19 Oct 6:10] MySQL Verification Team
Bug #108817 marked as duplicate of this one