Window service automatically get stopped due to error? - c#

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.

Related

Autostart workflow in sp2013 gets suspended with "There has been an error authenticating the request.", however

Let me try to describe the situation..
Site A:
Is meant is an catch all site, with only 1 library. This is used by an third party software, that send all the items to 1 location with specified information. Behind this is an timerjob, that sends all the items to their respective sites/libraries. (so doesn't stay on Site A)
Site X:
When an new item is added through the timerjob on Site A. An workflow is started, however the workflow is randomly sunspended with a the same error. A manual start on the same item will allways succeed. Thus only the autostart that gets suspended.
Workflow is made in visual studio and is widely used in the application without problems.
The error message:
Details: An unhandled exception occurred during the execution of the
workflow instance. Exception details: System.ApplicationException:
HTTP 401 {"error_description":"The server was unable to process the
request due to an internal error. For more information about the
error, either turn on IncludeExceptionDetailInFaults (either from
ServiceBehaviorAttribute or from the configuration
behavior) on the server in order to send the exception information
back to the client, or turn on tracing as per the Microsoft .NET
Framework SDK documentation and inspect the server trace logs."}
{"x-ms-diagnostics":["3001000;reason=\"There has been an error
authenticating the
request.\";category=\"invalid_client\""],"SPRequestGuid":["c0fb74e8-6b48-0deb-85c4-7fdab324d2f7"],"request-id":["c0fb74e8-6b48-0deb-85c4-7fdab324d2f7"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"SPRequestDuration":["17"],"SPIisLatency":["0"],"Server":["Microsoft-IIS/8.5"],"WWW-Authenticate":["Bearer
realm=\"97b27fa4-494a-4bff-a6a0-00b798335a86\",client_id=\"00000003-0000-0ff1-ce00-000000000000\",trusted_issuers=\"00000005-0000-0000-c000-000000000000#*,00000003-0000-0ff1-ce00-000000000000#97b27fa4-494a-4bff-a6a0-00b798335a86\"","Negotiate","NTLM"],"X-Powered-By":["ASP.NET"],"MicrosoftSharePointTeamServices":["15.0.0.4687"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1;
RequireReadOnly"],"Date":["Mon, 14 Jan 2019 13:47:12 GMT"]} at
Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext
context) at
System.Activities.CodeActivity.InternalExecute(ActivityInstance
instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
executor, BookmarkManager bookmarkManager, Location resultLocation)
Tried many given solutions (User Sync (however manual start with the same user is not a problem)), Workflow App Permissions feature ..

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

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

Windows form crash without any error, just error in Event log

I have problem with windows forms and multithreading. It is working for few minutes then crash without any error:
In event log I can find this:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Application Error" />
<EventID Qualifiers="0">1000</EventID>
<Level>2</Level>
<Task>100</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2013-12-26T10:12:47.000000000Z" />
<EventRecordID>23018</EventRecordID>
<Channel>Application</Channel>
<Computer>Mitja-Notebook</Computer>
<Security />
</System>
- <EventData>
<Data>NCrawler.Demo.exe</Data>
<Data>3.0.0.0</Data>
<Data>52bc0008</Data>
<Data>libcef.DLL</Data>
<Data>3.1650.1544.0</Data>
<Data>52a42238</Data>
<Data>c0000005</Data>
<Data>0014bd08</Data>
<Data>16b0</Data>
<Data>01cf0222620ef60a</Data>
<Data>D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\NCrawler.Demo\bin\Debug\NCrawler.Demo.exe</Data>
<Data>D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\NCrawler.Demo\bin\Debug\libcef.DLL</Data>
<Data>4487f3b0-6e16-11e3-a4f2-824ba6d84ade</Data>
</EventData>
</Event>
and
Wrong program name: NCrawler.Demo.exe, version: 3.0.0.0, timestamp: 0x52bc0008
Wrong module name: libcef.DLL, version: 3.1650.1544.0, timestamp: 0x52a42238
Exception code: 0xc0000005
Wrong path: D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\NCrawler.Demo\bin\Debug\NCrawler.Demo.exe
Wrong module path: D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\NCrawler.Demo\bin\Debug\libcef.DLL
What Can i do? How to find the real problem and solve it.
http://www.updatexp.com/0xC0000005.html
the Exception code 0xC0000005 Access Violation
A quick scan of the online technical forums and blogs reveal folks asking for help with this windows error. Your question may be the same as this typical request:
"An application error has occurred and an application error log is being generated. Exception: access violation (0xC0000005), Address"
The error 0xC0000005 is generated by an illegal "memory access violation". This can be caused by anything from faulty RAM, an incorrect/corrupt device driver, poorly written/updated software and more commonly under Windows XP Service pack 2, malware/adware installations.
Usually you get this error message when performing a specific task, and if that happens you need to check the corresponding 3rd party's website/support department to see if they are aware of the problem
..a while back Symantec Antivirus caused the 0xC0000005 error with an additional message about a file called SAVRT.SYS . A simple software update to the Symantec Antivirus cured the problem.

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