System.Messaging.MessageQueueException- External component has thrown an exception - c#

I run .exe through windows service which reads the message from Private Queue. The service is all good and stable but at times the service stops (it actually does not stop, but it is not processing anything. Service status is still "Started", I need to manually restart it).
This one doesn't show up often but analyzing the memory dump of the .exe file, I found that so many threads encountered below exception.
Exception object: 0000000001436120
Exception type: System.Messaging.MessageQueueException
Message: External component has
thrown an exception.
System.Messaging.MessageQueueException- External component has thrown an exception
System.Messaging.MessageQueue.ReceiveCurrent(System.TimeSpan, Int32, System.Messaging.Interop.CursorHandle, System.Messaging.MessagePropertyFilter, System.Messaging.MessageQueueTransaction, System.Messaging.MessageQueueTransactionType)
System.Messaging.MessageQueue.Peek(System.TimeSpan)
Any idea why service encounters this exception?? Thanks in advance

Related

What would cause AmqpException in azure wcf relay?

I am logging the connection status events with the wcf relay, and I'm seeing something like this in the logs.
1/26 06:47:12 ERROR Service Bus ConnectionStatus: 'Reconnecting' Event. [(null)][42]
LastError: System.ServiceModel.CommunicationException: Exception of type 'System.ServiceModel.CommunicationException' was thrown. ---> Microsoft.ServiceBus.Messaging.Amqp.AmqpException: An AMQP error occurred (condition='amqp:unauthorized-access').
--- End of inner exception stack trace ---
This exception doesn't show up in the list on this microsoft page, and the only other post I can find anywhere related to this error message is here. However, that post does not have any recent comments or a resolution or workaround for the issue. Also, the exception doesn't have any stacktrace, so how am I supposed to troubleshoot this error?
I guess as a follow-up, I would ask whether this is anything to actually worry about if the wcf connection is never faulting.
Apparently, the token that the relay keeps refreshing to stay active requires the time on the server to match the azure service that it is connecting with, and if not, this type of error will show up. We were able to fix it by correcting the server time.

WCF Rest Service unwanted Retry when throwing WebFaultException

I am using a WCF Rest service which is called via JS ajax calls.
For some methods if an exception occurs it is caught and wrapped in a WebFaultException which has the status code set to 500 (Internal Server Error) and is thrown.
For the methods that have this behavior we have noticed that the whole call chain that generated an exception at some point is retried for a seemingly random number of times, sometimes it's just once, other times 3, 5, even 7 before the control is passed back to the client side and the error message is shown.
The WebService runs in IIS, and if i hook the debugger to it the retry logic doesn't occur anymore probably because VisualStudio halts the execution due to the unhandled exception.
At first this behavior seem'd to point to WS-ReliableMessaging but from the documentation it should be enabled explicitly. Anb we are using a WebHttpBinding, which afaik is not supported.
If I change the Exception behavior to not throw WebFaultException then this behavior stops.
Why is this happening?

Window service automatically get stopped due to error?

I have an windows service that runs 24*7. This service use Renci.SshNet (third party dll) to connect to sftp server and downloading and uploading the files.
I got following information in event viewer. I check the log files and found that when this error come, the code was not running related to SFTP server.
I have written all the code in try catch block, so every error is logged into the log files.
Due to this error, windows service stopped.
I want to know the root cause of this issue and how I can modify the code so my service never get stopped again automatically.
Log Name: Application
Source: .NET Runtime
Date: 5/12/2012 10:49:12 AM
Event ID: 1026
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: FedEx-EDI-01
Description:
Application: Ess.SupplyChainService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.Sockets.SocketException
Stack:
at Renci.SshNet.Session.WaitHandle(System.Threading.WaitHandle)
at Renci.SshNet.Channels.Channel.Dispose(Boolean)
at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean)
at Renci.SshNet.Channels.Channel.Dispose()
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Finalize()
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name=".NET Runtime" />
<EventID Qualifiers="0">1026</EventID>
<Level>2</Level>
<Task>0</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2012-05-12T14:49:12.000Z" />
<EventRecordID>3723</EventRecordID>
<Channel>Application</Channel>
<Computer>FedEx-EDI-01</Computer>
<Security />
</System>
<EventData>
<Data>Application: Ess.SupplyChainService.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Net.Sockets.SocketException
Stack:
at Renci.SshNet.Session.WaitHandle(System.Threading.WaitHandle)
at Renci.SshNet.Channels.Channel.Dispose(Boolean)
at Renci.SshNet.Channels.ChannelSession.Dispose(Boolean)
at Renci.SshNet.Channels.Channel.Dispose()
at Renci.SshNet.Sftp.SubsystemSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SftpSession.Dispose(Boolean)
at Renci.SshNet.Sftp.SubsystemSession.Finalize()
</Data>
</EventData>
</Event>
You got a socket exception there - the stack trace you posted doesn't contain enough information as to why this happened.
Since the exception was not handled, the process terminated and of course the service stopped as result.
You need to find out why the exception occurred - add more logging and try to capture the incoming socket data.
An unhanded exception will bring your process down.
One answer is to handle the exception, but:
Just handling an exception does not ensure that the process is in a good state.
There is a small set of exceptions (eg. StackOverflowException) that cannot be caught: there is no way for a process to reliably return to a known state.
Alternatively:
Configure the service (via Services.msc) to restart on error,
Configure a tool like adplus (from Debugging Tools for Windows) to take a process dump on failure.
Uses those process dumps to fix the underlying errors.
According to the stack trace you provided, exception raised in finalization thread due to garbage collection (see "at Renci.SshNet.Sftp.SubsystemSession.Finalize" line in stack trace).
Because you can't catch this exception, it becomes unhanded and stops your process.
And that's why "the code was not running related to SFTP server".
Also, if you look at the stack trace more attentively, there's "at Renci.SshNet.Channels.Channel.Dispose()" line. This line means, that 3rd-party library developer trying to release managed resources during finalization. There are very little cases, when this is useful. But, in the same time, it is very dangerous and error-prone.
You should contact library developers.
As a temporary workaround you can setup service restart.
Windows services stops to work as any other app if there is unhandled exceptions, that is your case. Try to debug the code ( having the service running as a console application is my strategy, but you can use attach to process as well ) to check why the exception happens, and handle it properly: a service should recover in some reliable way, the restart on error option and friends should be used just as extreme solution, for instance if you don't own the code.

Application Net 1.1 about w3wp.exe memory leak in server

I have application web based net 1.1 Every three or four hour I have the restart my iis server because the performance becomes so slow , nothing will function with message memory leak. I traced the problem to the w3wp.exe in windows server 2003, Using the task manager, I can watch as memory is being added to this exe each time I open or refresh my web pages, but I never see memory released. Eventually there will be so much memory consumed, the web server will slow right down to nothing with display error memory leak and other message.
I don't know about solve that, I needed for monitoring memory used w3wp.exe so I can to release memory normal.
This Message
Server Error in '/myserver' Application.
Exception of type System.OutOfMemoryException was thrown.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown.]
Version Information: Microsoft .NET Framework Version:1.1.4322.2443; ASP.NET Version:1.1.4322.2470
Unfortunately, it isn't likely to be the w3wp.exe process itself, but the assemblies that it loads to run your application. I would check through your source code and make sure that you are releasing unmanaged resources, closing connections and disposing of IDisposable types.

Silent exception caught by IntelliTrace

Good afternoon,
I am running into a curious problem with WCF and IntelliTrace. I have an application that I'm testing using a locally-hosted WCF endpoint (the development server built into VS2010) using the basicHttpBinding. The application has been running normally: no exceptions are are making their way to the app and all of the WCF calls are returning data.
On a lark, I decided to take a look at the IntelliTrace output and noticed that my first call to WCF throws two exceptiosn:
Exception:Thrown: "No connection could be made because the target machine actively refused it" (System.Net.Sockets.SocketException)
A System.Net.Sockets.SocketException was thrown: "No connection could be made because the target machine actively refused it"
Exception:Caught: "No connection could be made because the target machine actively refused it" (System.Net.Sockets.SocketException)
A System.Net.Sockets.SocketException was caught: "No connection could be made because the target machine actively refused it"
I've reduced the application to a trivial use case:
ServiceClient client = new ServiceClient();
string[] output = client.LegacyCheck("username");
Console.WriteLine(output[0]);
Console.WriteLine(client.GetData(65));
And I get the same behavior. The second call has no exception associated with it.
I'm very puzzled. If the connection is being refused, then why does the exception not make it up to the application? And why would it success after 2 failed tries?
Any help is appreciated!
For what it's worth, I've noticed this behavior too with my IronPython/WPF applications. I've eventually realized that Intellitrace is simply showing you ALL of the exceptions that are raised and caught during normal operation, even if its part of a BCL or other library.
Of course, you only need to worry about unhandled exceptions (after they break your execution, you'll usually see those in IntelliTrace as a long chain of Thrown: Caught: Thrown: Caught: .... all the way down to Thrown: which will be the last line as the exception was not caught.
What I'm willing to bet is that the WCF code try's a couple of things first, catches the SocketExceptions, and then continues on its merry way. You wouldn't ever see this, but for IntelliTrace :)

Categories