473,396 Members | 2,109 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,396 software developers and data experts.

threadabortexception and web services

Hi,
I am running a web service which sometimes throws exceptions. I have a
lot of error trapping within the web service, but I have missed the current
problem. I am working on the current issue, but there even when I get this
fixed, there may be others I have not thought of. My immediate problem is
that the web service seems to throw a threadabortexception to the client when
it has an uncaught exception (I may be wrong. I am a bit confused about what
is being thrown and what is being caught and by whom) and I can't seem to
actually stop the threadabortexception. That is, I can catch it, and my error
handling is recording it approiately, but it still goes through and displays
an raw error for the client.
I have done some looking and threadabortexception seems to automatically
rethrow
(http://msdn2.microsoft.com/en-us/library/system.threading.threadabortexception.aspx)!
Anyone know the correct way to actually catch and stop a
threadabortexception?
Thanks!
Ethan
Jan 11 '07 #1
3 3306
"Ethan Strauss" <Et**********@discussions.microsoft.comwrote in message
news:EB**********************************@microsof t.com...
Sorry about the empty post. I don't know what happened...
Anyway, There should be only a single thread running at the time the error
has been thrown. The Web Service creates exactly two threads and then calls
the following
if ((!NTThread.Join(TimeOut)|| !RefSeqThread.Join(TimeOut)))
{
//Code to deal with time outs
}
The ThreadAbortException is being called after this point in the code.
I do not ever call thread.abort.
I do not create any more threads.
I think that means that both of those threads should be synchronized. Right?
Could one somehow be sneaking past this point without me realizing? Any other
ideas?
I may just patch it with a "Thread.ResetAbort", but I would prefer to get to
the root of the issue if I can.
Thanks!
Ethan

"Dave Sexton" wrote:
>Hi Ethan,

You should prevent the ThreadAbortException in the first place by not
killing the thread before it ends on its own.

You can use EventWaitHandles to synchronize threads. One can be used to
signal to a worker thread that it should stop gracefully by returning to the
caller, but the worker thread must periodically check the wait handle by
calling WaitOne(timeout).

Another option is to call Thread.ResetAbort, but if you do then you should
probably throw a different exception after cleaning up shared state, if
necessary. See the example in the link that you posted.

--
Dave Sexton
http://davesexton.com/blog

"Ethan Strauss" <Et**********@discussions.microsoft.comwrote in message
news:1E**********************************@microso ft.com...
Hi,
I am running a web service which sometimes throws exceptions. I have a
lot of error trapping within the web service, but I have missed the
current
problem. I am working on the current issue, but there even when I get this
fixed, there may be others I have not thought of. My immediate problem is
that the web service seems to throw a threadabortexception to the client
when
it has an uncaught exception (I may be wrong. I am a bit confused about
what
is being thrown and what is being caught and by whom) and I can't seem to
actually stop the threadabortexception. That is, I can catch it, and my
error
handling is recording it approiately, but it still goes through and
displays
an raw error for the client.
I have done some looking and threadabortexception seems to automatically
rethrow
(http://msdn2.microsoft.com/en-us/library/system.threading.threadabortexception.aspx)!
Anyone know the correct way to actually catch and stop a
threadabortexception?
Thanks!
Ethan



Look at Roman's suggestion, probably your webrequest takes too long to finish, and the
hosting process decided to unload the AD. Unloading an AD means aborting all thread running
inside it.

Willy.

Jan 11 '07 #2
Hi Ethan,
Anyway, There should be only a single thread running at the time the error
has been thrown. The Web Service creates exactly two threads and then
calls
the following
if ((!NTThread.Join(TimeOut)|| !RefSeqThread.Join(TimeOut)))
{
//Code to deal with time outs
}
The ThreadAbortException is being called after this point in the code.
I do not ever call thread.abort.
I do not create any more threads.
I think that means that both of those threads should be synchronized.
Right?
No. Synchronization means that shared state can be accessed safely by
multiple threads, usually with locks, or that their execution is
synchronized so that they can run in a controlled, serial manner, usually
with wait handles.

It's possible that the threads are synchronized, but it's not implicit just
by calling Join. All that does is block the calling thread until the joined
thread ends. Afterwards, your code does the same for another thread. In
the meantime, the threads could be messing up all sorts of shared state if
they aren't properly synchronized.
Could one somehow be sneaking past this point without me realizing? Any
other
ideas?
If you're specifying a time out value that elapses before one of the threads
ends, then yes. In your "code to deal with time outs", are you ending the
threads somehow or does the executing thread just continue on about its
business? I'm curious to knows what code goes there.
I may just patch it with a "Thread.ResetAbort", but I would prefer to get
to
the root of the issue if I can.
Roman's suggestion may be correct, as Willy pointed out, but to solve the
problem you're either going to have to use Thread.ResetAbort or increase the
timeout period for the request.

Is the client receiving the ThreadAbortException or some timeout exception?

I believe that a timeout indicates that your error may be related to the
AppDomain being unloaded, as was suggested by Willy, since the web service
won't wait for the abort exception; otherwise, I would assume that it's your
code causing the abort and not the service timing out since the service
would be expecting a response and instead receive the abort exception.

--
Dave Sexton
http://davesexton.com/blog

Jan 11 '07 #3
"Ethan Strauss" <Et**********@discussions.microsoft.comwrote in message
news:E7**********************************@microsof t.com...
Everyone, Thanks for all your help on this. This is the first time I have
ever done anything with threads and clearly it has complexities :-)

I am sure I am not running into timeout issues. This web service takes a
long time to run and I am tracking time outs quit carefully.

I think it has something to do errors causing AppDomian.Unload and that
calling thread.abort as was suggested earlier.

Don't worry about it. I will try to do some more reading.
Ethan

"Dave Sexton" wrote:
>Hi Ethan,
Anyway, There should be only a single thread running at the time the error
has been thrown. The Web Service creates exactly two threads and then
calls
the following
if ((!NTThread.Join(TimeOut)|| !RefSeqThread.Join(TimeOut)))
{
//Code to deal with time outs
}
The ThreadAbortException is being called after this point in the code.
I do not ever call thread.abort.
I do not create any more threads.
I think that means that both of those threads should be synchronized.
Right?

No. Synchronization means that shared state can be accessed safely by
multiple threads, usually with locks, or that their execution is
synchronized so that they can run in a controlled, serial manner, usually
with wait handles.

It's possible that the threads are synchronized, but it's not implicit just
by calling Join. All that does is block the calling thread until the joined
thread ends. Afterwards, your code does the same for another thread. In
the meantime, the threads could be messing up all sorts of shared state if
they aren't properly synchronized.
Could one somehow be sneaking past this point without me realizing? Any
other
ideas?

If you're specifying a time out value that elapses before one of the threads
ends, then yes. In your "code to deal with time outs", are you ending the
threads somehow or does the executing thread just continue on about its
business? I'm curious to knows what code goes there.
I may just patch it with a "Thread.ResetAbort", but I would prefer to get
to
the root of the issue if I can.

Roman's suggestion may be correct, as Willy pointed out, but to solve the
problem you're either going to have to use Thread.ResetAbort or increase the
timeout period for the request.

Is the client receiving the ThreadAbortException or some timeout exception?

I believe that a timeout indicates that your error may be related to the
AppDomain being unloaded, as was suggested by Willy, since the web service
won't wait for the abort exception; otherwise, I would assume that it's your
code causing the abort and not the service timing out since the service
would be expecting a response and instead receive the abort exception.

--
Dave Sexton
http://davesexton.com/blog

The asp.net hosting process keeps track of the web request running time, if it exceeds a
certain threshold, it will tear down the Application Domain which implies threadAbort
injections in all AD related threads. So, I'm pretty sure this is your issue.

Willy.

Jan 11 '07 #4

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

Similar topics

4
by: Vivek | last post by:
Hi, I have a question regarding ThreadAbortException. Why is the thread abort exception rethrown at the end of a catch clause? Why is ThreadAbortException's behavior designed to be this way? ...
6
by: David Waz... | last post by:
Moved an app from W/2000 Asp V1.0 to W/2003, VS/2003, ASPV 1.1 Page runs a long job, uploading 2 large fixed length files (300,000 rows) into SQL database. A process is run against the data,...
3
by: Steve - DND | last post by:
I just implemented a page that performs a Response.Redirect(url, true). As such, I wrapped it in a try catch, and explicitly caught a ThreadAbortException. However, the thread abort exception was...
4
by: splap20 | last post by:
Every day a large chunk of XML is posted up to my app via http. The app interprets this XML and writes results to a SQLServer. Occasionally a ThreadAbortException is thrown during this process....
1
by: Eric | last post by:
I have the following situation: I was getting intermittent errors using Reponse.Redirct("url", true) and was trying to catch the ThreadAbortException, but it was not staying caught and was showing...
1
by: Burak Gunay | last post by:
Hello, I have a piece of code where I am writing the contents of a datagrid to an excel report Dim tw As New StringWriter() Dim hw As New System.Web.UI.HtmlTextWriter(tw) Dim frm As HtmlForm...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
0
by: Zeba | last post by:
Hi ! I am using a httphandler to perform some url rewriting in my application. My web.config contains the following entry to direct all urls containing /App/*.ashx to my class AppHandler.cs in...
1
by: Morgan Cheng | last post by:
This question may look silly. We have a cluster of Frontend ASP.NET Web Service calls other cluster of other ASP.NET Web Services. There is a hardware F5 BigIP load balancer between these two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.