Solved

Handled Exception Stops Service On Windows 2008 Server

Posted on 2011-02-18
8
660 Views
Last Modified: 2012-05-11
I have a service running on a Windows 2008 Server. The service, using the Xceed FTP component, opens an FTP connection to a remote server and uploads a file. Sometimes a timeout exception is thrown. Altough the exception is handled by the service and is written its log file few second later Windows stops the service. In the Eventlog an entry From Windows Error Reporting with the same Timeout exception is written.

If the FTP component cannot open the connection (wrong PWD for example) an exception is also thrown but in this case the service continues its execution.

Disabling the Windows Error Reporting is not an option.
0
Comment
Question by:Borsec
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 34924717
Borsec:

can I see the ErroHandling of that TimeOut errorhandling ?
0
 

Author Comment

by:Borsec
ID: 34924906
FtpClient ftpClient = new FtpClient();
ftpClient.Timeout = 60;
try
{
      ftpClient.Connect(Server);
}
catch (Exception ex)
{
      "Could not connect to the host: " + Server;
}
try
{
      ftpClient.Login(User, Password);
}
catch (Exception ex)
{
      "Could not Login with user: " + User;
}
 try
{
      ftpClient.SendFile(file.FullName, file.Name);            
}
catch(Exception ex)
{
}

Error message:
1.  An I/O error occurred while accepting the FTP server's data connection.
Xceed.Ftp.FtpIOException: An I/O error occurred while accepting the FTP server's data connection. ---> System.Net.Sockets.SocketException: Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat IP:PortNr
   bei System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   bei Xceed.Ftp.Engine.PassiveFtpDataChannel.ConnectCompleted(IAsyncResult asyncResult)
   bei Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
   bei Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
   bei Xceed.Ftp.FtpClient.DoGetFolderContents(FtpCommandChannel commandChannel, ListFtpCommand listCommand)
   bei Xceed.Ftp.FtpClient.GetFolderContents(String remoteFileMask)
   
2. An error occurred while connecting to the FTP server.
Xceed.Ftp.FtpIOException: An error occurred while connecting to the FTP server. ---> System.Net.Sockets.SocketException: Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat Ip:PortNr
   bei System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   bei System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   bei Xceed.Ftp.Engine.FtpCommandChannel.Connect(IPEndPoint localAddress, IPEndPoint remoteAddress)
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei Xceed.Ftp.Engine.ConnectFtpCommand.EndExecute(IAsyncResult asyncResult)
   bei Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
   bei Xceed.Ftp.FtpClient.DoConnect(FtpCommandChannel commandChannel, ConnectFtpCommand command)
   bei Xceed.Ftp.FtpClient.Connect(String hostName)
   ...
   Could not connect to the host: Server
0
 
LVL 6

Expert Comment

by:t-max
ID: 34924964
Perhaps a script to check the service status (and restart it if stopped) is what you need?
http://www.techrepublic.com/forum/questions/101-274860
0
 

Author Comment

by:Borsec
ID: 34925017
we have tried this before and it's working, but we are looking for other solution.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 10

Accepted Solution

by:
John Claes earned 500 total points
ID: 34925610
Borsec.

You Should add the folowing part behind EVERY catch


Finally
{
      ftpClient.Close();
      return ;
}


First some info about this

The Finaly code is ran after the Catch and you can do some Cleanup
first we Close the ftpClient bacause some error has occured using it and it's corrupt.
So an other usage will return the same issue.
Then we get out of the Methode calling it so no further lines are used



==>

private sendFile (FileInfo file)
{
      FtpClient ftpClient = new FtpClient();
      ftpClient.Timeout = 60;
      try
      {
            ftpClient.Connect(Server);
      }
      catch (Exception ex)
      {
            "Could not connect to the host: " + Server;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }
      try
      {
            ftpClient.Login(User, Password);
      }
      catch (Exception ex)
      {
            "Could not Login with user: " + User;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }
      try
      {
            ftpClient.SendFile(file.FullName, file.Name);            
      }
      catch(Exception ex)
      {
            "Error occured during Sending File " + ex.Message;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }

}

regards
poor beggar
0
 
LVL 10

Expert Comment

by:John Claes
ID: 34940995
@Borsec:

Do you have any progress?

@t-max:
Restarting a Service when it's not running is not a solution only a Dirty Bug-Fix
You should always try to find the reason :

The reason here is that when he's try fails the we fly through the Catch and leave a broken connection let it dispose itself. (--> broken -> do something itself ???)


regards
poor beggar
0
 
LVL 6

Expert Comment

by:t-max
ID: 34941582
I agree with you poor beggar. However if the service wasn't written by you, and there's nothing wrong on your side, the only possible course of action is to restart the service until you figure out something else (changing software, talking to support for a solution, etc).
My solution was a simple workaround if the other stuff fails, but  I didn't say that before, so thanks for the constructive critic. All the best!
0
 
LVL 10

Expert Comment

by:John Claes
ID: 34941807
@t-max:
At that point you're right ;-)
If you don't have the code there is indeed no other way ;-(

Sorry If i seemed to be Rude
regards
poor beggar
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Many admins will agree: WSUS is is a nice invention but using it on the client side when updating a newly installed computer is still time consuming as you have to do several reboots and furthermore, the procedure of installing updates, rebooting an…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now