[CSHARP-4676] Connector crashes on attempting retrieve or update functions on the database for big-endian processor machines. Created: 12/Jun/23  Updated: 28/Oct/23  Resolved: 01/Aug/23

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.19.2
Fix Version/s: 2.21.0

Type: Bug Priority: Major - P3
Reporter: Manas Sahu Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Documentation Changes: Needed
Documentation Changes Summary:

Not sure whether to mention this in documentation or not...


 Description   

Summary

The MongoDB.Driver connects to the database on Big-endian machines (s390x in my case) and operations like collection create and delete work as expected but the connector crashes when attempting an insert or update operation.

How to Reproduce

using System;using MongoDB.Bson;using MongoDB.Driver;
namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            MongoClient dbClient = new MongoClient("mongodb://127.0.0.1:27017/");
            var database = dbClient.GetDatabase("sample_training");
            var collection = database.GetCollection<BsonDocument>("grades");
            var document = new BsonDocument
            {
                { "student_id", 1 },
                { "scores", new BsonArray
                    {
                    new BsonDocument{ {"type", "exam"}, {"score", 88.12334193287023 } },
                    new BsonDocument\{ {"type", "quiz"}, {"score", 74.92381029342834 } },
                    new BsonDocument\{ {"type", "homework"}, {"score", 89.97929384290324 } },
                    new BsonDocument\{ {"type", "homework"}, {"score", 82.12931030513218 } }
                    }
                },
                { "class_id", 480}
            };           
           collection.InsertOne(document);      
       }
    }
}

 

Additional Background

Error message:

Unhandled Exception:
System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 }, OperationsCountServerSelector }. Client view of cluster state is { ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "127.0.0.1:27017" }", EndPoint: "127.0.0.1:27017", ReasonChanged: "Heartbeat", State: "Disconnected", ServerVersion: , TopologyVersion: , Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server.
 ---> MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server.
 ---> System.FormatException: The size of the message is invalid.
   at MongoDB.Driver.Core.Connections.BinaryConnection.EnsureMessageSizeIsValid(Int32 messageSize)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(Int32 responseTo, CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.Dropbox.RemoveMessage(Int32 responseTo)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveBuffer(Int32 responseTo, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.ReceiveMessage(Int32 responseTo, IMessageEncoderSelector encoderSelector, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.HelloHelper.GetResult(IConnection connection, CommandWireProtocol`1 helloProtocol, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.ConnectionInitializer.SendHello(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelper(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Connections.BinaryConnection.Open(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.InitializeConnection(CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.Heartbeat(CancellationToken cancellationToken)", LastHeartbeatTimestamp: "2023-06-12T14:03:57.6330997Z", LastUpdateTimestamp: "2023-06-12T14:03:57.6331002Z" }] }.
   at MongoDB.Driver.Core.Clusters.Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
   at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
   at MongoDB.Driver.Core.Clusters.Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Clusters.Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
   at MongoDB.Driver.MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
   at MongoDB.Driver.MongoClient.StartImplicitSession(CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].UsingImplicitSession[BulkWriteResult`1](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionBase`1.<>c__DisplayClass68_0[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].<InsertOne>b__0(IEnumerable`1 requests, BulkWriteOptions bulkWriteOptions)
   at MongoDB.Driver.MongoCollectionBase`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].InsertOne(BsonDocument document, InsertOneOptions options, Action`2 bulkWrite)
   at MongoDB.Driver.MongoCollectionBase`1[[MongoDB.Bson.BsonDocument, MongoDB.Bson, Version=2.19.2.0, Culture=neutral, PublicKeyToken=null]].InsertOne(BsonDocument document, InsertOneOptions options, CancellationToken cancellationToken)
   at MongoDBCRUDExample.Program.Main(String[] args)

I have a fix ready for the bug.



 Comments   
Comment by Robert Stam [ 01/Aug/23 ]

Note that support for big-endian machines is unofficial for the time being. We think this code is correct but we don't currently test on big-endian machines. We do have very high confidence levels that these changes will not break anything on little-endian machines (which is also where all our tests currently run).

Comment by Githook User [ 01/Aug/23 ]

Author:

{'name': 'Manas Sahu', 'email': 'manas.sahu1@ibm.com', 'username': ''}

Message: CSHARP-4676: Add MongoDB.Driver support for big-endian clients.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/ed939013b8823220085c47c67bb306e23a4db6fb

Comment by James Kovacs [ 13/Jun/23 ]

Hi, manas.sahu.212@gmail.com,

Thank you for the PR. We will review it and reply with feedback.

Sincerely,
James

Comment by Manas Sahu [ 13/Jun/23 ]

Thank you for the response, James. I have raised a PR.

Regards,

Manas

Comment by James Kovacs [ 12/Jun/23 ]

Thank you for letting us know about this issue. We hadn't realized that Microsoft had introduced support for s390x with .NET 6. We appreciate you investigating this issue. You can create a pull request against our GitHub repository mentioning this ticket. Our team will review the PR and get back to you with next steps.

Sincerely,
James

Comment by Manas Sahu [ 12/Jun/23 ]

I have a fix ready for the issue and would request to be assigned to this ticket.

Comment by PM Bot [ 12/Jun/23 ]

Hi manas.sahu.212@gmail.com, thank you for reporting this issue! The team will look into it and get back to you soon.

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