[CSHARP-2792] Parsing compressors from the URI doesn't support snappy Created: 16/Oct/19  Updated: 21/Oct/19  Resolved: 21/Oct/19

Status: Closed
Project: C# Driver
Component/s: Wire Protocol
Affects Version/s: 2.9.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alex Bevilacqua Assignee: Vincent Kam (Inactive)
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Case:

 Description   

Setting snappy explicitly in the MongoClientSettings works, but parsing from the URI does not

Steps to repro:

1. mongod --networkMessageCompressors zlib,snappy --dbpath data
2. mongo --eval "db.setLogLevel(5,'network')"
3. Run the following in .NET Core 2.1 using the 2.9.2 driver:

[TestMethod]
public void TestDotNetCoreAndSnappyNetworkCompressor()
{
    var m = new MongoClient("mongodb://localhost:27017/?compressors=zlib&appName=zlibFromURI");
    var n = new MongoClient("mongodb://localhost:27017/?compressors=snappy&appName=snappyFromURI");
    var o = new MongoClient(new MongoClientSettings
    {
        Server = new MongoServerAddress("localhost", 27017),
        Compressors = new List<CompressorConfiguration> { new CompressorConfiguration(MongoDB.Driver.Core.Compression.CompressorType.Snappy) },
        ApplicationName = "snappyFromMongoClientSettings"
    });
    var coll = o.GetDatabase("test").GetCollection<BsonDocument>("foo");
    coll.InsertOne(BsonDocument.Parse("{x:1}"));
}

When reviewing the logs :

2019-10-16T15:10:24.633-0400 I CONTROL  [initandlisten] MongoDB starting : pid=19504 port=27017 dbpath=data 64-bit host=MEDIA-DESKTOP
2019-10-16T15:10:24.633-0400 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-10-16T15:10:24.633-0400 I CONTROL  [initandlisten] db version v4.0.11
2019-10-16T15:10:24.633-0400 I CONTROL  [initandlisten] git version: 417d1a712e9f040d54beca8e4943edce218e9a8c
2019-10-16T15:10:24.633-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten] modules: none
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten] build environment:
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten]     distarch: x86_64
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2019-10-16T15:10:24.634-0400 I CONTROL  [initandlisten] options: { net: { compression: { compressors: "zlib,snappy" } }, storage: { dbPath: "data" } }
2019-10-16T15:10:24.636-0400 I STORAGE  [initandlisten] Detected data files in data created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-10-16T15:10:24.637-0400 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7650M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-10-16T15:38:26.278-0400 I NETWORK  [conn13] received client metadata from 127.0.0.1:51831 conn13: { application: { name: "snappyFromURI" }, driver: { name: "mongo-csharp-driver", version: "2.9.2.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.18362", architecture: "x86_64", version: "10.0.18362" }, platform: ".NET Core 4.6.28008.01" }
2019-10-16T15:38:26.278-0400 I NETWORK  [conn14] received client metadata from 127.0.0.1:51830 conn14: { application: { name: "snappyFromMongoClientSettings" }, driver: { name: "mongo-csharp-driver", version: "2.9.2.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.18362", architecture: "x86_64", version: "10.0.18362" }, platform: ".NET Core 4.6.28008.01" }
2019-10-16T15:38:26.278-0400 I NETWORK  [conn15] received client metadata from 127.0.0.1:51832 conn15: { application: { name: "zlibFromURI" }, driver: { name: "mongo-csharp-driver", version: "2.9.2.0" }, os: { type: "Windows", name: "Microsoft Windows 10.0.18362", architecture: "x86_64", version: "10.0.18362" }, platform: ".NET Core 4.6.28008.01" }
2019-10-16T15:38:26.279-0400 D NETWORK  [conn13] Starting server-side compression negotiation
2019-10-16T15:38:26.279-0400 D NETWORK  [conn14] Starting server-side compression negotiation
2019-10-16T15:38:26.279-0400 D NETWORK  [conn15] Starting server-side compression negotiation
2019-10-16T15:38:26.280-0400 D NETWORK  [conn13] No compressors provided
2019-10-16T15:38:26.280-0400 D NETWORK  [conn14] snappy is supported
2019-10-16T15:38:26.280-0400 D NETWORK  [conn15] zlib is supported

When the Compressor is explicitely added as a new CompressorConfiguration is shows in the mongod log as supported, however as soon as you attempt an operation against it the connection will fail:

    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/localhost:28017" }", EndPoint: "Unspecified/localhost:28017", State: "Disconnected", Type: "Unknown", HeartbeatException: "System.NotSupportedException: Specified method is not supported.
       at MongoDB.Driver.Core.Compression.SnappyCompressor.Compress(Stream input, Stream output)
       at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.CompressedMessageBinaryEncoder.WriteMessage(CompressedMessage message)
       at MongoDB.Driver.Core.Connections.BinaryConnection.CompressMessages(IEnumerable`1 messages, IByteBuffer uncompressedBuffer, MessageEncoderSettings messageEncoderSettings)
       at MongoDB.Driver.Core.Connections.BinaryConnection.SendMessagesAsync(IEnumerable`1 messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Servers.ServerMonitor.GetHeartbeatInfoAsync(IConnection connection, CancellationToken cancellationToken)
       at MongoDB.Driver.Core.Servers.ServerMonitor.HeartbeatAsync(CancellationToken cancellationToken)", LastUpdateTimestamp: "2019-10-17T09:51:45.2500008Z" }] }.
  Stack Trace: 
    Cluster.ThrowTimeoutException(IServerSelector selector, ClusterDescription description)
    WaitForDescriptionChangedHelper.HandleCompletedTask(Task completedTask)
    Cluster.WaitForDescriptionChanged(IServerSelector selector, ClusterDescription description, Task descriptionChangedTask, TimeSpan timeout, CancellationToken cancellationToken)
    Cluster.SelectServer(IServerSelector selector, CancellationToken cancellationToken)
    MongoClient.AreSessionsSupportedAfterServerSelection(CancellationToken cancellationToken)
    MongoClient.AreSessionsSupported(CancellationToken cancellationToken)
    OperationExecutor.StartImplicitSession(CancellationToken cancellationToken)
    MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
    MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
    <>c__DisplayClass64_0.<InsertOne>b__0(IEnumerable`1 requests, BulkWriteOptions bulkWriteOptions)
    MongoCollectionBase`1.InsertOne(TDocument document, InsertOneOptions options, Action`2 bulkWrite)
    MongoCollectionBase`1.InsertOne(TDocument document, InsertOneOptions options, CancellationToken cancellationToken)
    UnitTest1.TestDotNetCoreAndSnappyNetworkCompressor() line 41

The above was from a standalone (which makes the HeartbeatException odd) and the following from a replicaset:

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 : "ReplicaSet", Type : "ReplicaSet", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/localhost:27017" }", EndPoint: "Unspecified/localhost:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "System.NotSupportedException: Specified method is not supported.
   at MongoDB.Driver.Core.Compression.SnappyCompressor.Compress(Stream input, Stream output)
   at MongoDB.Driver.Core.WireProtocol.Messages.Encoders.BinaryEncoders.CompressedMessageBinaryEncoder.WriteMessage(CompressedMessage message)
   at MongoDB.Driver.Core.Connections.BinaryConnection.CompressMessages(IEnumerable`1 messages, IByteBuffer uncompressedBuffer, MessageEncoderSettings messageEncoderSettings)
   at MongoDB.Driver.Core.Connections.BinaryConnection.SendMessagesAsync(IEnumerable`1 messages, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.ServerMonitor.GetHeartbeatInfoAsync(IConnection connection, CancellationToken cancellationToken)



 Comments   
Comment by Vincent Kam (Inactive) [ 21/Oct/19 ]

Hello alex.bevilacqua,

Thank you so much for your bug report! The third party library Snappy.NET that the driver relies on to provide Snappy compression only works on Windows and .NET Framework (not .NET Core). We are currently looking into options for expanding Snappy support to .NET Core on Windows as well as on other platforms (see CSHARP-2812 and CSHARP-2813)

Kind regards,

Vincent

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