OutOfMemoryException when disconnecting (1.8.0.0)

I am using Aspose.Email 1.8.0.0 to process some messages in a gmail inbox. The application is a console application and is scheduled to run periodically every 15 minutes. This works great most of the time but occasionally the process refuses to finish because the disconnect call hangs. The process eventually consumes all the available memory and shuts down but this can take up to a day. While this is happening the windows scheduler will not start any other process and hence the inbox is not processed.

The server is a Windows Server 2008 Web Edition with Service Pack 1.

The code I am using is pretty simple.

var client = new ImapClient("imap.gmail.com", 993, username, password) { EnableSsl = true, SecurityMode = ImapSslSecurityMode.Implicit }; client.Connect(true);

client.SelectFolder(ImapFolderInfo.InBox, true);

// Process unread messages in inbox

client.Disconnect();


Here is the exception I am receiving.


System.OutOfMemoryException: Insufficient memory to continue the execution of the program.

   at System.Text.StringBuilder.ExpandByABlock(Int32 minBlockCharCount)
   at System.Text.StringBuilder.Append(Char* value, Int32 valueCount)
   at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32 charCount)
   at ›  .‹ .– (‰  , Boolean , String )
   at ›  .‰ .– ()
   at ›  .  .Send(†  , String , Int32 )
   at ›  .  .Send(†  , String )
   at Aspose.Email.Imap.ImapClient.Disconnect()

Regards,
Paul.

Hi Paul,


Thank you very much for using Aspose.Email for .NET 1.8.0.

This issue is quite complex to debug as its not possible to re-generate same scenario here. It requires same OS with same hardware specifications and may be same gmail account as some specific email can also be the reason.

However I will try to simulate the same environment here to sort out this issue I will arrange Windows Server 2008 Web Edition. First I will try this OS with my some sample gmail account using windows scheduler and your piece of code. If found something important, will share with you.

In the meanwhile can you please try some different combinations like changing the PC on which this application is running. Also PC with different OS and hardware configuration may also help us to narrow down the problem. I would also suggest to check different email account for a while and share your findings if something important is observed.

Can you please let me know how much RAM is there in your system?

I regret any inconvenience caused to you and we will be more than happy to provide support to resolve this issue.

Best Regards

This is currently happening at this moment again on our live server.

The server has 8Gb of memory. It is currently at 40% utilisation and the process is now taking up 400Mb and growing at a rate of approximately 50Kb per second. It will eventually crash with an out of memory exception if I leave it running.

Can you not add logging (e.g. Log4Net) to determine why the problem is happening, or at the very least force the disconnect to happen within a timeout? Because the code is obfuscated I can't see what it is trying to do but I can only imagine it is stuck in some sort of infinite loop with a memory leak.

Hi Paul,


We are working to establish environment to regenerate the issue.

Can you please let me know the average activity on your gmail account. How many mails are being sent and received while this issue arises so that while re-generating the scenario we perform activities with same frequency.

Thank you very much for your patience and understanding.

Best Regards

Hi Paul,


We have recently published Aspose.Email for .NET v1.9.0. Could you be kind enough to test your scenario with the latest assemblies and feed us back with your results.

Thank you for your cooperation.