We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Imap async methods create too many Imap connections- overdrawing the default limit of 16 on Exchange

Hello,
We are using Aspose.Email 4.0.0 and trying to fetch, process and delete emails out of an inbox through Imap client. I use asynchronous functions to fetch more emails in parallel, but limit it to 5 at a time. We hit a major problem in production when using this with Exchange server, it has a limit o 16 imap connections from a single IP, and it seems the Aspose client opens more connections than it should and depletes all 16, hitting an exception: Aspose.Email.Imap.ImapException: 004 NO LOGIN failed.

I tried to fix this and used Aspose.Email 4.3.0, but it still depletes all the connections, it doesn't produce the exception anymore, but at the point where it reaches too many, Exchange will stop responding and the Fetch task never completes. Here is a sample code that does an async list messages and fetches the first 10 of them asynchronously again and again, just for simplicity and reproducing it. Within minutes, this code reaches the 16 imap connections (you can check them via nestat command) and the program stops.
private static ImapClient imap = new ImapClient("exchange.ysoft.com", 143, "***", "***") { EnableSsl = false };
public static void Main() {
while (true) {
var list = Task.Factory.FromAsync(imap.BeginListMessages(), imap.EndListMessages).Result;
Console.WriteLine("Count: " + list.Count);
Fetch10(list);
}
}

static void Fetch10(ImapMessageInfoCollection list) {
Task[] fetches = new Task[10];
for (int i = 0; i < 10; i++)
fetches[i] = Fetch(list[i].UniqueId);
Task.WaitAll(fetches);
foreach (var fetch in fetches) Console.WriteLine("Subject: " + fetch.Result.Subject);
}

static Task Fetch(string id) {
return Task.Factory.FromAsync(imap.BeginFetchMessage(id), imap.EndFetchMessage);
}


There must be some leak in the async Imap implementation that creates more connections than it should need, at any point in time there are no more than 10 asynchronous methods being called/awaited. In our real code we only do 5 and it last for hours but eventually fails as well.

Martin

P.S. I wish you hadn't introduced a class named Task into the Aspose.Email namespace, that conflicts with a .NET framework one and it forced me to use fully quantified names everywhere :(

Hi Martin,


Thank you for sharing your concern with us.

I was able to reproduce this issue at my end using the latest version of Aspose.Email for .NET 4.3.0 and have logged it as NETWORKNET-34421 in our issue tracking system for further investigation by our development team. Once there is any information available in this regard, we’ll update you here via this thread.

We are sorry for the inconvenience caused to you.

Thank you, I hope it can be fixed soon, I tried even switching to completely synchronous email processing without any parallelism, simple stupid code like


var messages = client.ListMessages()
foreach (var message in messages) {
Process(client.FetchMessage(message.Id));
client.DeleteMessage(message.Id);
}

being called on each timer tick, and the number of imap connections steadily growing with coming emails… The only workaround I found is to disconnect the ImapClient on every tick, but that hurts performance significantly, this is becoming a huge problem for us…

Martin

Hi Martin,


Thank you for sharing more information. I have passed it to developers for their reference.

The issues you have found earlier (filed as NETWORKNET-34421) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
If I use all synchronous processing, this is indeed fixed, but if I run the exact asynchronous example that I wrote in the first post, it behaves even worse than before, I wonder if they tried to run it before they said "fixed". It's just an endless loop that fetches 10 messages and writes out their subject, but when I run it, very soon it either stops processing altogether, or throws this exception: "The given key was not present in the dictionary."

This means I can't use this version at all unless I am willing to switch to completely synchronous processing, I really expect more from a professional solution.

Martin

Hi Martin,


Thank you for providing the feedback. However, I was unable to reproduce this issue with the latest version of Aspose.Email for .NET 4.4.0 at my end. Could you please make sure if the new DLL is properly referenced in your application? My inbox contains around 100 email messages and the loop goes on without any exception at my end.