[CSHARP-2005] Invalid BinaryConnection state transition from 4 to Failed Created: 19/Jun/17  Updated: 28/Oct/23  Resolved: 12/Oct/18

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

Type: Bug Priority: Minor - P4
Reporter: Aristarkh Zagorodnikov Assignee: Robert Stam
Resolution: Fixed Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-2212 Invalid BinaryConnection state transi... Closed

 Description   

After upgrading to 2.4.4 it appears that the problem mentioned in CSHARP-1961 still persists.

When the replicaset failover is triggered, the following exceptions happen:

System.InvalidOperationException: Invalid BinaryConnection state transition from 4 to Failed.
MongoDB.Driver.Core.Connections.BinaryConnection.OpenConnectionHelper.FailedOpeningConnection(Exception wrappedException)
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)
MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken cancellationToken)
MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool.AcquiredConnection.Open(CancellationToken cancellationToken)
MongoDB.Driver.Core.Servers.Server.GetChannel(CancellationToken cancellationToken)
MongoDB.Driver.Core.Bindings.ServerChannelSource.GetChannel(CancellationToken cancellationToken)
MongoDB.Driver.Core.Bindings.ChannelSourceHandle.GetChannel(CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.FindOperation`1.Execute(IReadBinding binding, CancellationToken cancellationToken)
MongoDB.Driver.MongoCursor`1.GetEnumerator()



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

Author:

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

Message: CSHARP-2005: Invalid BinaryConnection state transition from 4 to Failed.
Branch: v2.7.x
https://github.com/mongodb/mongo-csharp-driver/commit/0ff5b05af63b8cffa1dcd2343bc6ba93beadd8b5

Comment by Brian Buvinghausen [ 25/Oct/18 ]

I'm getting REALLY tired of seeing this error in our logs....

System.InvalidOperationException: Invalid BinaryConnection state transition from 4 to Failed. at MongoDB.Driver.Core.Connections.BinaryConnection.OpenConnectionHelper.FailedOpeningConnection(Exception wrappedException) at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken) at MongoDB.Driver.Core.Servers.Server.GetChannelAsync(CancellationToken cancellationToken) at MongoDB.Driver.Core.Operations.AggregateOperation`1.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken) at MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync[TResult](IReadBinding binding, IReadOperation`1 operation, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl`1.ExecuteReadOperationAsync[TResult](IClientSessionHandle session, IReadOperation`1 operation, ReadPreference readPreference, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl`1.AggregateAsync[TResult](IClientSessionHandle session, PipelineDefinition`2 pipeline, AggregateOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSessionAsync[TResult](Func`2 funcAsync, CancellationToken cancellationToken) at MongoDB.Driver.AsyncCursorHelper.SingleOrDefaultAsync[T](Task`1 cursorTask, CancellationToken cancellationToken)

Comment by Brian Buvinghausen [ 24/Oct/18 ]

Robert,

Do you know when 2.7.1 will be published to Nuget? We're still getting the errors and anxiously await deploying this fix.

Thanks,
Brian

Comment by Githook User [ 12/Oct/18 ]

Author:

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

Message: CSHARP-2005: Invalid BinaryConnection state transition from 4 to Failed.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/f6e1667b6a23f5234b8e13c580e297b46dd586e9

Comment by Robert Stam [ 11/Oct/18 ]

This is indeed a bug in the BinaryConnection class.

But... it's a bug that would only affect a single connection (sometimes).

In all our tests against replica sets the driver is always able to find the new primary after an election occurs. That's not to say that there aren't any bugs in the failover logic, just that whatever bugs that exist aren't encountered very often and are hard to reproduce.

The impact of this bug is that the new exception ("Invalid BinaryConnection state transition from 4 to Failed") is hiding some other exception that really indicates what went wrong with this one connection.

Once this bug is fixed the original exception will be preserved and we will be able to see what the original exception was (it's very likely that the original exception was that the server closed the socket, which it will do when a primary steps down).

Comment by Brian Buvinghausen [ 17/Sep/18 ]

Can I get anyone to acknowledge this or provide an update? When we have a problem in the replica set this takes the entire website down and we have to restart.  This is NOT going to work long term.

Comment by Brian Buvinghausen [ 14/Sep/18 ]

One of our nodes in our Mongo Atlas replica set went down and we're experiencing this problem on driver version 2.7.0

So my question is since the C# driver cannot successfully failover what is the purpose of having a replica set? It seems like I've tripled my chance to fail.  How has this issue been open for 16 months?

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