[CSHARP-2435] Ignore PlatformNotSupportedException when configuring KeepAlive Created: 09/Nov/18  Updated: 28/Oct/23  Resolved: 09/Nov/18

Status: Closed
Project: C# Driver
Component/s: Connectivity
Affects Version/s: 2.7.1
Fix Version/s: 2.7.2

Type: Bug Priority: Blocker - P1
Reporter: Marek Kotolowski Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Azure web app for containers - linux docker image.



 Description   

After upgrading to the latest C# driver 2.7.1, the dotnet core 2.1 web application using the mongo driver and running on Azure Web apps for containers (linux docker image), cannot start up any more. I am getting the exception below:

2018-11-09T10:30:58.459115820Z Application startup exception: System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "1", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/xdb.1.xxx.com:27017" }", EndPoint: "Unspecified/xdb.1.xxx.com:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.PlatformNotSupportedException: Socket.IOControl handles Windows-specific control codes and is not supported on this platform.
2018-11-09T10:30:58.459144120Z    at System.Net.Sockets.SocketPal.WindowsIoctl(SafeCloseSocket handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)
2018-11-09T10:30:58.459148920Z    at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
2018-11-09T10:30:58.459152821Z    at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateSocket(EndPoint endPoint)
2018-11-09T10:30:58.459156621Z    at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)
2018-11-09T10:30:58.459160521Z    at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
2018-11-09T10:30:58.459172721Z    --- End of inner exception stack trace ---
2018-11-09T10:30:58.459176421Z    at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
2018-11-09T10:30:58.459180921Z    at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)" }, { ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/xdb.2.xxx.com:27017" }", EndPoint: "Unspecified/xdb.2.xxx.com:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.PlatformNotSupportedException: Socket.IOControl handles Windows-specific control codes and is not supported on this platform.
2018-11-09T10:30:58.459185621Z    at System.Net.Sockets.SocketPal.WindowsIoctl(SafeCloseSocket handle, Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue, Int32& optionLength)
2018-11-09T10:30:58.459189321Z    at System.Net.Sockets.Socket.IOControl(Int32 ioControlCode, Byte[] optionInValue, Byte[] optionOutValue)
2018-11-09T10:30:58.459192721Z    at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateSocket(EndPoint endPoint)
2018-11-09T10:30:58.459196121Z    at MongoDB.Driver.Core.Connections.TcpStreamFactory.CreateStreamAsync(EndPoint endPoint, CancellationToken cancellationToken)
2018-11-09T10:30:58.459199621Z    at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
2018-11-09T10:30:58.459203021Z    --- End of inner exception stack trace ---
2018-11-09T10:30:58.459206421Z    at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
2018-11-09T10:30:58.459209921Z    at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)" }] }.
2018-11-09T10:30:58.459213321Z    at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
2018-11-09T10:30:58.459216821Z    at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
2018-11-09T10:30:58.459220221Z    at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
2018-11-09T10:30:58.459224021Z    at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
2018-11-09T10:30:58.459227421Z    at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
2018-11-09T10:30:58.459231621Z    at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
2018-11-09T10:30:58.459235021Z    at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
2018-11-09T10:30:58.459238521Z    at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
2018-11-09T10:30:58.459242221Z    at MongoDB.Driver.MongoCollectionImpl`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
2018-11-09T10:30:58.459248621Z    at MongoDB.Driver.FilteredMongoCollectionBase`1.FindSync[TProjection](FilterDefinition`1 filter, FindOptions`2 options, CancellationToken cancellationToken)
2018-11-09T10:30:58.459252321Z    at MongoDB.Driver.FindFluent`2.ToCursor(CancellationToken cancellationToken)
2018-11-09T10:30:58.459255721Z    at MongoDB.Driver.IAsyncCursorSourceExtensions.ToList[TDocument](IAsyncCursorSource`1 source, CancellationToken cancellationToken)



 Comments   
Comment by Githook User [ 09/Nov/18 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-2435: Ignore PlatformNotSupportedException when configuring KeepAlive.
Branch: v2.7.x
https://github.com/mongodb/mongo-csharp-driver/commit/a6e556384e5bc293fe87816b2f70bdcdae0e71f3

Comment by Githook User [ 09/Nov/18 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-2435: Ignore PlatformNotSupportedException when configuring KeepAlive.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e92a8d45544ed31f73c270ddc2e2696b207e62ba

Comment by Robert Stam [ 09/Nov/18 ]

Since the online documentation is unclear about where IOControl and/or SetSocketOption are supported (and with which parameters), the workaround we are planning on is for the driver to protect itself against PlatformNotSupportedExceptions.

We will first attempt to turn on KeepAlive and set the KeepAliveValues by calling IOControl (as we currently do in 2.7.1). If that throws a PlatformNotSupportedException we will then attempt to turn on KeepAlive by calling SetSocketOption (which will use the system default KeepAliveValues). If SetSocketOption also throws a PlatformNotSupportedException we will just give up trying to configure KeepAlive and use the socket as is.

Comment by Robert Stam [ 09/Nov/18 ]

Thank you for reporting this.

We will find a workaround as quickly as possible and release 2.7.2 very soon.

Comment by Marek Kotolowski [ 09/Nov/18 ]

Possibly related issue in the dotnet corefx issue list:
https://github.com/dotnet/corefx/issues/25467
It was closed without any resolution.

Generated at Wed Feb 07 21:42:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.