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

"Thread static buffer is already in use." error after bad utf8 string write.

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.23.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • 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?

      Summary

      After an error with invalid unicode strings the thread is unable to perform operations on MongoDB.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      MongoDB C# 2.10

      How to Reproduce

      Will PR on github.

        [Fact]
        public void GetBytesUsingThreadStaticBuffer_should_leave_the_thread_operational()
       

      {       var invalidUtf8String = "🔥".Substring(0, 1);       var exception = Record.Exception(() => EncodingHelper.GetBytesUsingThreadStaticBuffer(Utf8Encodings.Strict, invalidUtf8String));       var e = exception.Should().BeOfType<EncoderFallbackException>().Subject;       using var segment = EncodingHelper.GetBytesUsingThreadStaticBuffer(Utf8Encodings.Strict, "Thread static buffer should not be in use");       segment.Segment.Array.Length.Should().Be(256);   }

      Additional Background

      1. Call to rent buffer with invalid utf8 string
      2. encoding.GetBytes throws (using strict encoder)
      3. disposable is not created, thread static attributes holing buffer
      4. every subsequent call in this thread throws

            Assignee:
            adelin.mbidaowona@mongodb.com Adelin Mbida Owona
            Reporter:
            mtb.snowboard@gmail.com Andrea Balducci
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: