Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-5065

Dispose RawBsonDocument in ExplicitEncryptionLibMongoCryptController.UnwrapValue

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.26.0
    • Affects Version/s: None
    • Component/s: None
    • Dotnet Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      CSHARP-4669 noted high memory usage when using FLE with GridFS. A forums user noticed the following:

      The EncryptField and EncryptFieldAsync methods both call UnwrapValue, which is:

      private BsonValue UnwrapValue(byte[] encryptedWrappedBytes)
      {
          var rawDocument = new RawBsonDocument(encryptedWrappedBytes);
          return rawDocument["v"];
      }
      

      As RawBsonDocument is IDisposable, it should be surrounded by a using clause:

      private BsonValue UnwrapValue(byte[] encryptedWrappedBytes)
      {
          using var rawDocument = new RawBsonDocument(encryptedWrappedBytes);
          return rawDocument["v"];
      }
      

      We should implement this improvement and verify that it reduces memory usage when using FLE with large documents such as GridFS.

            Assignee:
            adelin.mbidaowona@mongodb.com Adelin Mbida Owona
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: