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

Free Support Forum - aspose.com

Imapclient Method does not return

Problem: When connected to a gmail, I have noticed ImapClent methods including (ListMessages, SelectFolder and FetchMessage) not return. In this sceneraio cpu utlization stays high and and memory usage keeps growing. Attaching Windbg i was able to observed what seemed like network stream read was being done repeatedly (infinitlely) with the buffer size growing.

What might be cauing this behavior?

Is there any way to cancel / terminate an operation?

What is the purpose of specifying the timeout property on ImapClient?

Thanks

Hi,


Thank you for your inquiry.

Your said issue is very strange to me cause I have never encountered such problem. Can you please share your sample source code for your review. Also please mention the version of Aspose.Email for .NET that you are currently using. We will look into this matter very soon.

The TimeOut property for ImapClient refers to the time in milliseconds after which if no response received from server, the application will disconnect automatically.

I am running 1.0.0.0 of Aspose.Email.

Sample code of the method that runs frequently like once every 5 mins, The problem occurs transiently after several hours or even days sometimes:

public void DownloadAndProcessEmailMessages()
{
try
{
if (Connect())
{
foreach (ImapMessageInfo imapMessageInfo in ListInBoxMessages())
{
DownloadAndProcessMessage(imapMessageInfo, emailStoreProcessing);
}
}
}
catch(ImapOperationTimeoutException iote)
{
try
{
Disconnect();
}
catch(Exception e)
{
Log(logPrefix + "DownloadAndProcessEmailMessages exception handler encountered exception " + e.Message + " during Disconnect");
}
finally
{
_imapClient = null;
}
}
}


private IEnumerable ListInBoxMessages()
{
SelectFolder(_inboxFolderName);
if (DoImapOperationsAsynchronously)
{
IAsyncResult listMessagesResult = _imapClient.BeginListMessages(null, null);
try
{
if (listMessagesResult.AsyncWaitHandle.WaitOne(DefaultImapOperationTimout))
return _imapClient.EndListMessages(listMessagesResult);
else
{
throw new ImapOperationTimeoutException(
"Imap operation for listing Inbox Messages did not respond in timely manner");
}
}
finally
{
listMessagesResult.AsyncWaitHandle.Close();
}
}
return _imapClient.ListMessages();
}

private void SelectFolder(string folderName)
{
try
{
Log(logPrefix + "Imap Selecting Folder " + folderName);
if (DoImapOperationsAsynchronously)
{
IAsyncResult selectFolderResult = _imapClient.BeginSelectFolder(_inboxFolderName, false, null, null);
try
{
if (selectFolderResult.AsyncWaitHandle.WaitOne(DefaultImapOperationTimout))
_imapClient.EndSelectFolder(selectFolderResult);
else
{
ThrowImapTimeoutException(logPrefix + "Imap operation for selecting folder " + folderName +
" did not respond in timely manner");
}
}
finally
{
selectFolderResult.AsyncWaitHandle.Close();
}
}
else
_imapClient.SelectFolder(_inboxFolderName, false);
Log(logPrefix + "There are " + _imapClient.CurrentFolder.TotalMessageCount + " messages in " + folderName);
}
catch (ImapException imapException)
{
throw new DownloadMessageException("Failed to Select ImapFolder " + folderName, imapException);
}
}

private MailMessage FetchMessage(ImapMessageInfo imapMessageInfo)
{
try
{
Log(logPrefix + "Imap FetchMessage uniqueid " + imapMessageInfo.UniqueId + " : sequence number " + imapMessageInfo.SequenceNumber);
if (DoImapOperationsAsynchronously)
{
IAsyncResult fetchMessageResult = _imapClient.BeginFetchMessage(imapMessageInfo.SequenceNumber, null, null);
try
{
if(fetchMessageResult.AsyncWaitHandle.WaitOne(FetchMessageTimeout))
{
return _imapClient.EndFetchMessage(fetchMessageResult);
}
else
ThrowImapTimeoutException(logPrefix + "Imap operation Fetch Message " + imapMessageInfo.UniqueId +
" did not respond in timely manner");
}
finally
{
fetchMessageResult.AsyncWaitHandle.Close();
}
}
else
return _imapClient.FetchMessage(imapMessageInfo.UniqueId);
}
catch (ImapException imapException)
{
throw new DownloadMessageException("Failed to Fetch Message " + imapMessageInfo.UniqueId, imapException);
}
return null;
}

Hi,


Thank you for the further information and your source code.

We will try to replicate the issue on our end by creating a service with your provided source code and by setting the trigger time of 5mins. Meanwhile, can you please get the latest version of Aspose.Email for .NET v1.2.0 and test your scenario by just replacing the assemblies with latest version.

Please feed us back with your results.

Thank you.

I have some additional information that might help debug.

Windbg CLR Stack and PE (print exception) outputs: Note the PrintException stack stops at Aspose_Email!›.‹.†‘(‰.œ, Byte[], Int32, Int32)+0x1f7
Maybe that method is catching SocketException and continuing.

0:032> !clrstack
OS Thread Id: 0x18f0 (32)
Child-SP RetAddr Call Site
0000000022d1cae8 000007fef77b604a System.Net.Sockets.NetworkStream.Read(Byte[], Int32, Int32)
0000000022d1caf0 000007fef77b940b System.Net.FixedSizeReader.ReadPacket(Byte[], Int32, Int32)
0000000022d1cb40 000007fef77b9178 System.Net.Security._SslStream.StartFrameHeader(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)
0000000022d1cbb0 000007fef77b8e32 System.Net.Security._SslStream.StartReading(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)
0000000022d1cc30 000007fef77b8bc9 System.Net.Security._SslStream.ProcessRead(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)
0000000022d1cce0 000007ff004d820d System.Net.Security.SslStream.Read(Byte[], Int32, Int32)
0000000022d1cd30 000007ff004d81b4 ‰.’.Read(Byte[], Int32, Int32)
0000000022d1cd80 000007ff004d8161 ‰.‡.Read(Byte[], Int32, Int32)
0000000022d1cdb0 000007ff004d7d46 ‰.œ.Read(Byte[], Int32, Int32)
0000000022d1ce10 000007ff004d6ff5 ›.‹.†‘(‰.œ, Byte[], Int32, Int32)
0000000022d1cec0 000007ff004da5ca ›.‹.–(›.‰, Boolean, System.String)
0000000022d1d010 000007ff004da321 ›.‰.–()
0000000022d1d040 000007ff004e1b4b ›..Send(›.†, System.String)
0000000022d1d080 000007ff004e0375 ›.Send(›.†)
0000000022d1d110 000007ff004dfff7 Aspose.Email.Imap.ImapClient.SelectFolder(System.String, Boolean)
0000000022d1d1a0 000007ff004df974 InBoundEmail.AsposeEmailClient.SelectFolder(System.String, InBoundEmail.IEmailStoreProcessing)
0000000022d1d300 000007ff004df12c InBoundEmail.AsposeEmailClient.ListInBoxMessages(InBoundEmail.IEmailStoreProcessing)
0000000022d1d3f0 000007ff004de8ca InBoundEmail.AsposeEmailClient.DownloadAndProcessEmailMessages(InBoundEmail.IEmailStoreProcessing)
0000000022d1d610 000007ff004c5447 InBoundEmail.InBoundEmailProcessor.Process()
0000000022d1d840 000007fef82bdd38 InBoundEmail.InBoundEmailProcessor.DoWork()
0000000022d1da00 000007fef98fe382 System.Threading.ExecutionContext.runTryCode(System.Object)
0000000022d1e2b0 000007fef833a8dd System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
0000000022d1e300 000007fef98fe382 System.Threading.ThreadHelper.ThreadStart()

0:032> !pe
Exception object: 000000000e42f9d8
Exception type: System.IO.IOException
Message: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.
InnerException: System.Net.Sockets.SocketException, use !PrintException 000000000e42f380 to see more
StackTrace (generated):
SP IP Function
0000000022D1AB20 000007FEF7E6FBF0 System_ni!System.Net.Sockets.NetworkStream.Read(Byte[], Int32, Int32)+0x6c4400
0000000022D1CAF0 000007FEF77B604B System_ni!System.Net.FixedSizeReader.ReadPacket(Byte[], Int32, Int32)+0x3b
0000000022D1CB40 000007FEF77B940C System_ni!System.Net.Security._SslStream.StartFrameHeader(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)+0x6c
0000000022D1CBB0 000007FEF77B9179 System_ni!System.Net.Security._SslStream.StartReading(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)+0x69
0000000022D1CC30 000007FEF77B8F35 System_ni!System.Net.Security._SslStream.ProcessRead(Byte[], Int32, Int32, System.Net.AsyncProtocolRequest)+0x275
0000000022D1CCE0 000007FEF77B8BCA System_ni!System.Net.Security.SslStream.Read(Byte[], Int32, Int32)+0x3a
0000000022D1CD30 000007FF004D820E Aspose_Email!‰.’.Read(Byte[], Int32, Int32)+0x2e
0000000022D1CD80 000007FF004D81B5 Aspose_Email!‰.‡.Read(Byte[], Int32, Int32)+0x15
0000000022D1CDB0 000007FF004D8162 Aspose_Email!‰.œ.Read(Byte[], Int32, Int32)+0x82
0000000022D1CE10 000007FF004D7D47 Aspose_Email!›.‹.†‘(‰.œ, Byte[], Int32, Int32)+0x1f7

StackTraceString:
HResult: 80131620

Hi,


I am afraid, we are unable to replicate your said issue on our end by using latest version of Aspose.Email for .NET v1.2.0. In fact we are waiting for your results with this latest assembly. Have you tried Aspose.Email for .NET v1.2.0?

Currently we are testing your source code (slightly changed in order to compile) with Gmail Imap server. It would be of great help that you provide a working sample console application that could replicate the problem.

Thank you for your understanding.

[EDITED] we are setting DefaultImapOperationTimout = 10000