Free Support Forum - aspose.com

Memory leak in unauthenticated smtp client

We have this product embedded in a server and after a certain amount of activity, we are getting out-of-memory exceptions:
2018/04/23 04:01:47.586 | 2580 | 6 | Exception caught: AsposeException: Failure sending mail.
—> Aspose.Email.Clients.Smtp.SmtpException: Failure sending mail. —> System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at #=qt8x7ZvZdu0ww4Zb8K3sQymFj2eLVIMcD4uqcnU0RfGozy5bUrSXbXghnCPdBgDx6.#=qzIXtucc_8IfRxMKsw$pPNw==(Stream #=qkynvc45_69AIsyf9zh$0qg==, Stream #=qRt_gXrNnRkvGthJ_CVo9og==, Int32 #=quvczAlSf621q7ITgZli_fA==)
at #=qh9VCxShMjHvKKNdypSnv3tTBPpFia$k2e_5GESkhTko=.#=q35KpiPYAHHBo462CoCy67w==(#=qFsq7GojLBe6BvDJf0jqDFFNNjb6$SXvw3ndnfvbyZ8I= #=qSMsYkrLvgox8qV8nG17STQ==, Boolean #=qUPbbWj7pK3yvt0wWckfyEA==)
at #=qNvZi6$_oSVSOq2HNuUyYyhonJQjj4p2oB7U63KVVNaY=.#=q35KpiPYAHHBo462CoCy67w==(#=qFsq7GojLBe6BvDJf0jqDFFNNjb6$SXvw3ndnfvbyZ8I= #=qSMsYkrLvgox8qV8nG17STQ==)
at Aspose.Email.MailMessage.#=q35KpiPYAHHBo462CoCy67w==(#=qFsq7GojLBe6BvDJf0jqDFFNNjb6$SXvw3ndnfvbyZ8I= #=qSMsYkrLvgox8qV8nG17STQ==)
at Aspose.Email.MailMessage.Save(Stream stream, SaveOptions options)
at Aspose.Email.MailMessage.Save(Stream stream)
at Aspose.Email.MailMessage.#=qcfu$yurg9iQBgsHf7lT5Gw==(Stream #=qCYdsKnQHIlZxXGljaNOsUQ==)
at Aspose.Email.MailMessage.Save(Stream stream, SaveOptions options)
at Aspose.Email.Clients.Smtp.SmtpClient.#=qQDUrv_2rZQQXgJD2pCZV1Q==(IConnection #=qnOv75bTdoSModdWgG7wzBQ==, IEnumerable1 #=qLUThhCRerKSqM9oMfdtJhA==, EventHandler1 #=qG6YVpS8fWhMG6064MvYSYHgPZZqF1dZZ_PPnGpGtcZ8=)

However, we are only getting these exceptions when using an unauthenticated smtp configuration. I have attached a small test project designed to run with the 18.4 version of aspose.email.dll to illustrate the issue. This project simply sends an email message in an infinite loop (constructing and destructing the aspose objects every time it is sent). The leak isn’t great but after 50-100 messages or so, a 3 MB array is allocated in the LOH that is never released.

Switching to the authenticated smtp client, and the program runs without increasing in memory.asposeTestingApp.zip (3.6 KB)

Note the exception call stack is from version 17.5 but I was able to duplicate the memory leak in both 17.5 & 18.4.

@ReportsNow,

We executed your sample application but it raised Connection exception as username and password was not specified for the SmtpClient. Could you please share if the code works as it is at your end? If not, please make the revised project that we can use to reproduce the problem at our end. Also, please share the steps to observe the memory leak in VS or in Task Manager.

Kashif,

Instructions to use app:

  1. Open up project in VS and open up Program.cs and set license.
  2. Build the project in VS. I’m using VS 2017 but should work in VS 2015
  3. Configure an SMTP relay server that allows unauthenticated connections (i.e. no need to use user/password).
  4. Command line: <smtp mail server name> <smtp port> <from address> <to address> <subject> <body>
  5. Turn on VS diagnostics (Options|Debugging|General|Enable Diagnostic Tools while debugging)
  6. Run the app in debug using appropriate command line arguments from step 3.
  7. After debug starts, open up diagnostics window (Debug|Windows|Show Diagnostics Tools)
  8. Go to the diagnostics window and click on the ‘Memory Usage’ tab. Take an initial snapshot.
  9. Let test app run. It will send an email every 2 seconds. Make other snapshots every 20-30 sends. You can then click on the Heap Size and compare with the previous snapshots and you will notice 3 MB arrays getting slowly allocated and not freed over time.

To see the configuration that doesn’t leak, comment out lines 19 & 20 and uncomment out 21 & 22. Configure a traditional smtp server requiring user/password. Then use the following command line: <smtp mail server name> <smtp port> <from address> <to address> <subject> <body> <smtp user> <smtp password>.

Example for setting up a relay with an O365 account and IIS: https://support.office.com/en-us/article/how-to-configure-iis-for-relay-with-office-365-eb57abd2-3859-4e79-b721-2ed1f0f579c9

While working with our customer, it appears this leak can also be replicated with an SMTP server using NTLM authentication (again, not requiring user/password but, instead, passing Windows user credentials automatically). From the smtp logs: “Smtp client[1|4/29/2018 11:01:57 PM]: AUTH NTLM …”

@ReportsNow,

Thank you for providing us detailed description. We are working on it and request you to spare us time to configure the environment. We will write back here once environment is established and issue is observed here.

Just checking to see if you have made progress on setting the needed smtp environment up for testing.

@ReportsNow,

We will soon share our findings with you here. We regret the delay caused in this regard due to the unavailability of required environment. We appreciate your little more patience in this regard.

@ReportsNow,

This is to update you that the problem has been reported as EMAILNET-38986 for further investigation. We’ll update you here once there is some information or a fix version available in this regard.

The issues you have found earlier (filed as EMAILNET-38986) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal