[CSHARP-2067] TcpStreamFactory.ConnectAsync should use Socket.ConnectAsync Created: 17/Oct/17  Updated: 28/Oct/23  Resolved: 23/Oct/18

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

Type: Improvement Priority: Minor - P4
Reporter: Gian Maria Ricci Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When TcpStreamFactory.ConnectAsync was first implemented the .NET Core implementation of Socket did not have a ConnectAsync method so it was simulated by using Task.Run.

Our current dependency for the .NET Standard artifacts of the .NET driver is on .NET Standard 1.5, which does support Socket.ConnectAsync.

So we can update our code to use Socket.ConnectAsync now that it is available.

Note: see pull request.

Original Description

I have a project with xunit and dotnetcore, and during unit testing I have the below exception only if

1) I use not localhost but the IP of the machine
2) I use multithread testing (if I execute unit test sequentially everyting is ok).

I've debugged the driver and I'll submit a pull request.

A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = WritableServerSelector, 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 : "10.0.0.40:27017" }

", EndPoint: "10.0.0.40:27017", State: "Disconnected", Type: "Unknown" }] }.



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

Author:

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

Message: CSHARP-2067: Added Gian Maria Ricci to the contributors list.
Branch: v2.7.x
https://github.com/mongodb/mongo-csharp-driver/commit/156ece78f31c59f43f1942e7dba282381e3f4171

Comment by Githook User [ 06/Nov/18 ]

Author:

{'name': 'Gian Maria Ricci', 'email': 'ricci.gianmaria@gmail.com', 'username': 'alkampfergit'}

Message: CSHARP-2067: TcpStreamFactory.ConnectAsync should use Socket.ConnectAsync
Branch: v2.7.x
https://github.com/mongodb/mongo-csharp-driver/commit/fe9ff1f89c006ff826b685c3dc77b763abd9eb02

Comment by Githook User [ 23/Oct/18 ]

Author:

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

Message: CSHARP-2067: Added Gian Maria Ricci to the contributors list.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e21e59c0e464cc324bc134060b165ec1e93b2b78

Comment by Githook User [ 23/Oct/18 ]

Author:

{'name': 'Gian Maria Ricci', 'email': 'ricci.gianmaria@gmail.com', 'username': 'alkampfergit'}

Message: CSHARP-2067: TcpStreamFactory.ConnectAsync should use Socket.ConnectAsync
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/185125ffc9d4db9b6bb04e766eda6c17befea84b

Comment by Sebastian Alonso [ 30/Oct/17 ]

Hi @alkampfer we are facing the same problem here, running the mongo driver inside aspnet core webapi (from vs2017 or dotnet windows command line or even inside docker containers) is just fine, but the timeout exception is triggered when running tests with xunit and connecting to a remote mongodb via IP (the mongodb server is running inside a docker container).

Will this PR be merged soon?

Thanks

Comment by Gian Maria Ricci [ 17/Oct/17 ]

I've done a pull request, that in my specific situation solves the problem: https://github.com/mongodb/mongo-csharp-driver/pull/297

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