Undocumented exception *very* occasionally occurs in background thread in my ASP.NET app!

Hi,

I'm doing some background threading in an ASP.NET application, and just now experienced the background thread crashing with the following stack trace:

System.Threading.ThreadStopException: Thread was being stopped.
  at System.String.GetHashCode()
  at System.Collections.Hashtable.GetHash(Object key)
  at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
  at System.Collections.Hashtable.set_Item(Object key, Object value)

There rest of the stack trace is my application code, which as you understand attempted to add a value to a hashtable. I don't really think the reason the exception occured has anything to do with the String.GetHashCode() implementation, but I can't reproduce it so there's no way to tell.

Another interesting thing to note is the exception type - searching for "ThreadStopException" in the MSDN library as well as MSDN online results in no matches! Since it is undocumented I have no idea why it is thrown - or rather, why the thread is "being stopped". I'm not doing anything to attempt stopping (or even aborting, which should anyway result in a ThreadAbortException, which *is* documented) the thread.

Does anyone have the faintest idea what I can do to find out of this


Answer this question

Undocumented exception *very* occasionally occurs in background thread in my ASP.NET app!

  • Steve Hills

    Hi!

     

    HashTable may fail if you pass null as key. Also you may have doing some cross-thread access to that hashtable so it broken from inside (HashTable are not multithreading safe in general - synchronization is our task). String by itself are thread safe (because it's immutable), so I think problem in hash table usage pattern.

    Also I remember that ASP.NET run thread to respond query, create page inside thread, load, render and terminate thread after that. Are you sure that you main thread alive at the time you run inside second thread And do you really need second thread in ASP.NET Why

    Can you post more code about using that HashTable



  • Photius

    Thanks for trying to help, but unfortunately this doesn't really explain things. Passing null as key to the Hashtable results in a NullReferenceException. And if you look at the stack trace, clearly it was passed a non-null string, or else the GetHashCode() method wouldn't have been invoked, right

    I think that we'll need someone who has intimate knowledge of the .Net FrameWork/CLR internals, beyond what is documented behavior. The fact that ThreadStopException is undocumented tells me I was never supposed to see it, which in turn probably means I've run into a bug in either Framework or runtime.

  • Damiaan

    Hi!

    Thanks for asking! I'm a member of the ASP.NET team, and was just popping over here to see what was going on. The best place to ask ASP.NET questions is over on the ASP.NET forums at http://www.asp.net/welcome.aspx tabindex=1&tabid=39

    HTH,

    PEte



  • BobCa

    Sorry you feel that I didn't take the time to answer. I try to answer as many questions as I can, but there are times when I don't know the answer, or am not sure where to start, and unfortunately, this was one of those cases.

    I know there are many experts in this area on the ASP.NET forums, so rather than trying to give you something that is just patently wrong, I figured the best thing to do was just refer you to the ASP.NET fourms.



  • MichaelHight

    Hi Pete,

    I will try that. Pity you couldn't take the time to comment on the issue in addition to promoting the other site.

    Btw I also wonder how it came about that your post was marked as answering my question; after all it didn't even attempt..

  • Undocumented exception *very* occasionally occurs in background thread in my ASP.NET app!