question

arunkumar-8518 avatar image
0 Votes"
arunkumar-8518 asked MayankBargali-MSFT answered

the underlying compression routine could not reserve sufficient memory

Hi All,

I am trying to process messages from the service bus queue. So basically my handler unzips the message and process. I have come with the below to unzip but i seeing a lot of messages sitting int he dead letter queue with the error message "the underlying compression routine could not reserve sufficient memory". Appreciate if you could please comment on the code below? App insights failures are pointing me to the Unzip method below.

 public static class StringCompression
     {
         public static void CopyTo(Stream src, Stream dest)
         {
             var bytes = new byte[4096];
    
             int cnt;
    
             while ((cnt = src.Read(bytes, 0, bytes.Length)) != 0)
             {
                 dest.Write(bytes, 0, cnt);
             }
         }
    
         public static string Unzip(byte[] bytes)
         {
             using (var msi = new MemoryStream(bytes))
             using (var mso = new MemoryStream())
             {
                 using (var gs = new GZipStream(msi, CompressionMode.Decompress))
                 {
                     //gs.CopyTo(mso);
                     CopyTo(gs, mso);
                 }
    
                 return Encoding.UTF8.GetString(mso.ToArray());
             }
         }
    
         public static byte[] Zip(string str)
         {
             var bytes = Encoding.UTF8.GetBytes(str);
    
             using (var msi = new MemoryStream(bytes))
             using (var mso = new MemoryStream())
             {
                 using (var gs = new GZipStream(mso, CompressionMode.Compress))
                 {
                     //msi.CopyTo(gs);
                     CopyTo(msi, gs);
                 }
    
                 return mso.ToArray();
             }
         }
     }
dotnet-csharpazure-service-bus
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered

Hi @arunkumar-8518

Welcome to Microsoft Q&A! Thanks for posting the question.
I can see that "dotnet-csharp" tag is already added to your question and I will wait for the dot net experts to comment/review on your code and why the exception is observed.

From the service bus end as you have mentioned that the messages are moved to the dead letter queue then you can use service bus explorer to view the reason for the dead letter of the messages. There can be different reasons for a message to be dead lettered and you can review this article for different reason the message moved to DLQ.

As you have mentioned that there are exceptions "the underlying compression routine could not reserve sufficient memory" in your client application then the reason I could think would be your client application have locked the message but was not able to call complete/abounded call as there was expectation while unzips the message and processing. Most probably the dead letter reason would be "Max delivery count exceeded" but you can double-check it using service bus explorer.

I have done some quick search and looks like the error is observed when there are compatibility issues with the .net framework. I will suggest you to review it and see if it helps you. You can also post your query in stackoverflow where the dot net experts can provide their input.

Reference: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/application-compatibility

Feel free to get back to me if you need any assistance from azure service bus end.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.