[GH-ISSUE #3] exchange-catchall possibly crashing MSExchangeTransport #3

Closed
opened 2026-02-27 15:44:54 +03:00 by kerem · 8 comments
Owner

Originally created by @pgale on GitHub (Mar 5, 2014).
Original GitHub issue: https://github.com/Pro/exchange-catchall/issues/3

Not sure if this is the fault of exchange-catchall. Every 3 or 4 days I see this exception error and exchange stops processing mail. I also have GFI mail essentials installed and that reports email placed in a failed mail folder as it can't process. The errors are:

An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs)
   at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke()
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState)
   at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult).
An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs)
   at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke()
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState)
   at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult)
   at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state)
   at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken)
   at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult).
An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs)
   at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke()
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state)
   at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState)
   at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult)
   at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state)
   at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken)
   at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state)
   at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult)
   at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state)
   at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken)
   at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state)

Is that something to do with catchall?

Thanks.

Originally created by @pgale on GitHub (Mar 5, 2014). Original GitHub issue: https://github.com/Pro/exchange-catchall/issues/3 Not sure if this is the fault of exchange-catchall. Every 3 or 4 days I see this exception error and exchange stops processing mail. I also have GFI mail essentials installed and that reports email placed in a failed mail folder as it can't process. The errors are: ``` An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs) at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke() at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState) at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult). ``` ``` An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs) at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke() at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState) at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult) at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state) at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken) at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken) at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult). ``` ``` An exception was thrown while processing data from client IP address 192.168.0.14. The exception is System.ArgumentException: An item with the same key has already been added. at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Exchange.CatchAll.CatchAllAgent.RcptToHandler(ReceiveCommandEventSource source, RcptCommandEventArgs rcptArgs) at Microsoft.Exchange.Data.Transport.Smtp.SmtpReceiveAgent.Invoke(String eventTopic, Object source, Object e) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.Dispatcher.Invoke(MExSession session) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.Invoke() at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.AsyncInvoke(Object state) at Microsoft.Exchange.Data.Transport.Internal.MExRuntime.MExSession.BeginInvoke(String topic, Object source, Object e, AsyncCallback callback, Object callbackState) at Microsoft.Exchange.Protocols.Smtp.SmtpCommand.BeginRaiseEvent(AsyncCallback callback, Object state) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.StartProcessingCommand(Byte[] inputBuffer, Int32 offset, Int32 size, Boolean overflow) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult) at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state) at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken) at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken) at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state) at Microsoft.Exchange.Protocols.Smtp.SmtpInSession.ReadLineComplete(IAsyncResult asyncResult) at Microsoft.Exchange.Net.LazyAsyncResult.WorkerThreadComplete(Object state) at Microsoft.Exchange.Net.LazyAsyncResult.Complete(IntPtr userToken) at Microsoft.Exchange.Net.LazyAsyncResult.ProtectedInvokeCallback(Object value, IntPtr userToken) at Microsoft.Exchange.Net.NetworkConnection.BeginReadLine(AsyncCallback callback, Object state) ``` Is that something to do with catchall? Thanks.
kerem 2026-02-27 15:44:54 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@damien-giry commented on GitHub (Mar 5, 2014):

I have the same type of messages. Is it SP1 or exchange-catchall? It seems to start with the installation of exchange-catchall. By the way I only have exchange-catchall as an external transport agent.

<!-- gh-comment-id:36782326 --> @damien-giry commented on GitHub (Mar 5, 2014): I have the same type of messages. Is it SP1 or exchange-catchall? It seems to start with the installation of exchange-catchall. By the way I only have exchange-catchall as an external transport agent.
Author
Owner

@pgale commented on GitHub (Mar 5, 2014):

Looking at the logs in more detail, it's actually crashing quite regularly except most of the time MSExchange Transport restarts OK - some times it doesn't though which is when everything stops and I notice.

<!-- gh-comment-id:36784987 --> @pgale commented on GitHub (Mar 5, 2014): Looking at the logs in more detail, it's actually crashing quite regularly except most of the time MSExchange Transport restarts OK - some times it doesn't though which is when everything stops and I notice.
Author
Owner

@damien-giry commented on GitHub (Mar 5, 2014):

Did you patched your exchange SP1? http://windowsitpro.com/blog/exchange-2013-sp1-bug-breaks-third-party-products
I have just applied the patch to see if it change something.

<!-- gh-comment-id:36789018 --> @damien-giry commented on GitHub (Mar 5, 2014): Did you patched your exchange SP1? http://windowsitpro.com/blog/exchange-2013-sp1-bug-breaks-third-party-products I have just applied the patch to see if it change something.
Author
Owner

@Pro commented on GitHub (Mar 5, 2014):

You are using Exchange 2013 SP1, correct? I'll try to test it in a VM with this version...
I'm using Exchange 2010 SP3 and Catchall for at least a year and didn't ran in this bug.

@pgale What does "crashes quite regularly" mean exactly? A specific time span (e.g. every 5 minutes) or each time an email arrives?

According to the exception messages it looks like exchange-catchall is causing the exception in the Exchange.CatchAll.CatchAllAgent.RcptToHandler function.
I suspect the line 217 to cause the exception: github.com/Pro/exchange-catchall@9fc7fd5540/CatchAllAgent/CatchAllAgent.cs (L217)
(because it is the only one having anything to do with a Dictionary causing the exception)

The origToMapping object is used to save the original recipient (the E-Mail address the sender used) for later usage to set the X-OrigTo header (which can't be done directly in the RcptTo handler).

It looks like the RcptToHandler method is called multiple times for the same E-Mail which shouldn't happen.

Anyways I'll check if there's a better alternative for uniquely identifying a MailItem instead of using GetHashCode() (which isn't a unique identifier: http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx).
Using a better identifier and checking if the ID already exists in the dictionary should fix the problem.

Give me a few days to (hopefully) fix this. If you have any suggestions feel free to mention them 👍

<!-- gh-comment-id:36805760 --> @Pro commented on GitHub (Mar 5, 2014): You are using Exchange 2013 SP1, correct? I'll try to test it in a VM with this version... I'm using Exchange 2010 SP3 and Catchall for at least a year and didn't ran in this bug. @pgale What does "crashes quite regularly" mean exactly? A specific time span (e.g. every 5 minutes) or each time an email arrives? According to the exception messages it looks like `exchange-catchall` is causing the exception in the `Exchange.CatchAll.CatchAllAgent.RcptToHandler` function. I suspect the line 217 to cause the exception: https://github.com/Pro/exchange-catchall/blob/9fc7fd55400d5feb32a0f986ec03b81d3e85aff6/CatchAllAgent/CatchAllAgent.cs#L217 (because it is the only one having anything to do with a Dictionary causing the exception) The `origToMapping` object is used to save the original recipient (the E-Mail address the sender used) for later usage to set the `X-OrigTo` header (which can't be done directly in the RcptTo handler). It looks like the `RcptToHandler` method is called multiple times for the same E-Mail which shouldn't happen. Anyways I'll check if there's a better alternative for uniquely identifying a `MailItem` instead of using `GetHashCode()` (which isn't a unique identifier: http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx). Using a better identifier and checking if the ID already exists in the dictionary should fix the problem. Give me a few days to (hopefully) fix this. If you have any suggestions feel free to mention them :+1:
Author
Owner

@Pro commented on GitHub (Mar 5, 2014):

I quick-fixed the issue with the commits above.

You can use the following .dll (just replace it with your existing one) in the meantime so you can still get E-Mails (for Exchange 2013 SP1 only!!): https://github.com/Pro/exchange-catchall/raw/5a78b01a84f9b25d52c76a0969ca80186f3834dc/CatchAllAgent/bin/Exchange%202013%20SP1/ExchangeCatchAll.dll

(The X-OrigTo header is disabled in this version).

Please let me know if you still get any exceptions!

<!-- gh-comment-id:36807484 --> @Pro commented on GitHub (Mar 5, 2014): I quick-fixed the issue with the commits above. You can use the following .dll (just replace it with your existing one) in the meantime so you can still get E-Mails (for Exchange 2013 SP1 only!!): https://github.com/Pro/exchange-catchall/raw/5a78b01a84f9b25d52c76a0969ca80186f3834dc/CatchAllAgent/bin/Exchange%202013%20SP1/ExchangeCatchAll.dll (The `X-OrigTo` header is disabled in this version). Please let me know if you still get any exceptions!
Author
Owner

@pgale commented on GitHub (Mar 6, 2014):

Yes using 2013 SP1 and with GFI mailessentials anti spam installed.
I was getting exceptions every 20-30 minutes it seemed.
I have installed the .DLL and am monitoring... good so far
BTW - small typo in caught email in event log - 'Caught' spelt wrongly.
Many thanks for the super quick support :)
Paul.

<!-- gh-comment-id:36834681 --> @pgale commented on GitHub (Mar 6, 2014): Yes using 2013 SP1 and with GFI mailessentials anti spam installed. I was getting exceptions every 20-30 minutes it seemed. I have installed the .DLL and am monitoring... good so far BTW - small typo in caught email in event log - 'Caught' spelt wrongly. Many thanks for the super quick support :) Paul.
Author
Owner

@pgale commented on GitHub (Mar 10, 2014):

Just to let you know - the new version has been running fine for the last 4 days or so with no more errors :)

<!-- gh-comment-id:37163197 --> @pgale commented on GitHub (Mar 10, 2014): Just to let you know - the new version has been running fine for the last 4 days or so with no more errors :)
Author
Owner

@Pro commented on GitHub (Mar 10, 2014):

This should now be fixed in version 1.6.0. Before updating, please read: https://github.com/Pro/exchange-catchall#updating-to-version-160 (Thanks for the typo hint)

<!-- gh-comment-id:37243179 --> @Pro commented on GitHub (Mar 10, 2014): This should now be fixed in version 1.6.0. Before updating, please read: https://github.com/Pro/exchange-catchall#updating-to-version-160 (Thanks for the typo hint)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/exchange-catchall#3
No description provided.