473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Errors in services. How should you handle them?

I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll. TCP
is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be sited
in places where there are power outages. I expect the network to go down
etc.
Should users be alerted if connection can't be achieved? When?
Nov 17 '05 #1
4 1341
Unfortunately Claire, only you can decide if and when you should notify
someone.

Once you have decided the ifs and whens, the next question becomes the hows
and whats. i.e. How do I notify the notifiee and what do I notify them of.
The answers to these are dictated by the mechanisms that are available to
your service and what information is available. Basically, it will come down
to personal preference.
"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll.
TCP is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be
sited in places where there are power outages. I expect the network to go
down etc.
Should users be alerted if connection can't be achieved? When?

Nov 17 '05 #2
On Fri, 1 Apr 2005 08:05:19 +0100, Claire wrote:
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll. TCP
is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be sited
in places where there are power outages. I expect the network to go down
etc.
Should users be alerted if connection can't be achieved? When?


I wrote a lot of service applications in the past (in C++). What I can tell
you from experience:
- use logfiles (or log to a database), where you log the
important things happening in your service
- alert someone, if a severe error happens that needs
user/administrator interaction in anyway.
- make it configurable (who is alerted, when, etc.)

In a .NET application, I strongly suggest to use Log4Net
(http://logging.apache.org/log4net) to do that. Using log4net you also get
very good configuration possibilities to configure what kind of errors are
logged to which device and when shall someone (and who) be alerted.

Instead of Log4Net you could also use the Logging Appliaction Block of the
Enterprise Library
(http://msdn.microsoft.com/library/de...ml/entlib.asp).

hth
--
Claudio Grazioli
http://www.grazioli.ch
Nov 17 '05 #3
I wrote a similar service for an enterprise application that dealt with the
same kinds of problems you are facing here: power outtages, lost
connections, etc. Here are a few things to keep in mind while you design
your service:

1) Make your service fail safe from the stand point that if network is not
available it can just idle and periodically check for network availability,
your service should not "hang" or "crash" if the network goes down. This
will involve wrapping all of your network calls with error handlers so that
you won't be using any sockets that are disconnected or in an invalid state.

2) Logs are really useful. If possible log all acitivity to a local
database. For example: Service start time, service shutdown time, and if
the network goes up and down log the time the network became unavailable and
when it was detected up again. Log messages are extremely useful when you
have to trace through a problem that may not be necessarily happening with
your code/design but instead with the network that is connected to the
server.

3) Assign priority to log entries such as Notice, Caution, and Critical
depending on the kinds of problems you foresee encountering during operation
of the server. In the product I worked on the logs were available through a
web interface and color coded accordingly, it was very easy to go straight
to critical and see what happened leading up to that critical log.

4) If your service is going to be multithreaded you add another dimension of
complexity. This is not a bad thing but you must make sure that your
service main thread is able to recycle threads that crash or terminate
unexpectedly. You should be able to gracefully deallocate the memory from a
crashed thread and respawn it to continue what it had been doing previously.
This is not something that is trivial to do.

5) Lastly don't leave any connections open in an environment like this.
Crashing because of a power outtage may actually corrupt the files or
databases for which you are writing to when it happens. So when making
entries into a database or file, if it is not a performance hit go with the
open->write->close sequence and try to make each transaction as atomic as it
can be.

Project I worked on ran a multithreaded service in a fairly hostile
environment where it received data from one end, processed the data, and
sent data to another end point where it needed to be able to detect if the
data received was valid (not garbled) and that the receving system was
available (not crashed) and if not it would have to queue the data until it
became available (each transaction carried a $$$ amount so no transactions
could be lost). In addition locations were often hostile at the very least
and prone to lightning strikes and other hazards, go figure systems running
in closets at air force bases.

This is really long, but I hope it will give you a few things to consider as
you design your system.

Alex
"Claire" <as*******@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I'm writing a realtime monitoring application acting as a Windows service.
This service communicates to some instrumentation via a third party dll.
TCP is the transport mechanism over the network.
What I want to know is how should errors be handled in Windows services? I
foresee problems with this sort of application, especially with the tcp
side.
The service should be able to recover from errors as it's going to be
sited in places where there are power outages. I expect the network to go
down etc.
Should users be alerted if connection can't be achieved? When?

Nov 17 '05 #4
Thanks to everyone
Yes Alex, just sounds like my system except I don't have direct access to
the ports as I have to communicate via the instrument vendors DLL ;o(
I just hope the developer's code is well behaved.

Claire
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Francis Lavoie | last post by:
Is it possible to restart windows services? (remotely and locally) Because I have a little script that retreive the LastWaitTimeout key of the automatic update, delete that key if it out schedule...
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
6
by: Aaron | last post by:
I would like to write a program that finds all asp.net errors in iis logs? what characteristics should i look for? (a line in the log that has the error?) what about sql errors? Thanks in...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
2
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now...
4
by: Christoph Duesmann | last post by:
Hi ! I wan't to code a service which will be installed on some clients in our network. The service should have the following features : - Scan all properties of the Client (Hardware, Software...
3
by: clintonb | last post by:
Some programmers, and even Microsoft documents, say you should only throw exceptions for exceptional situations. So how are others handling all the other unexceptional errors? How are you...
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.