473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deadlock in a multithread C# application

I am currently debugging a deadlock in a multithread C# application. It
makes lots of calls to legacy unmanaged code. The application runs on windows
sever 2003 and uses the sever version of the CLR. The application runs on
..NET 1.1 SP1.

When the deadlock happens the process is using 0 CPU.

I was able to collect crash dumps and have been trying to make sense out of
them using windbg.

!threads show PreEmptive GC is disabled for both thread 20 and 26. There are
other threads running (all have PreEmptive GC enabled) but I did not display
them here to keep this shorter.

PreEmptive GC Alloc
Lock
ID ThreadOBJ State GC Context Domain
Count APT Exception
20 0x1658 0x16e083d0 0x1800222 Disabled 0x01275044:0x01 276a64 0x001498b8
1 MTA (Threadpool Worker) System.NullRefe renceException
26 0x958 0x414274c0 0x1800220 Disabled 0x0d327830:0x0d 327844 0x001498b8
2 MTA (GC) (Threadpool Worker) System.NullRefe renceException
Here is the clrstack for thread 26. ttGetRteVarVari ation is unmanaged code.
Looks like it had a problem and a exception (probably a
NullReferenceEx ception) was thrown. There are GCFrames in the middle so I
begin to wonder if the GC is involved.

ESP EIP
0x40bae194 0x7c82ed54 [FRAME: HelperMethodFra me]
0x40bae1c0 0x799ef4fc [DEFAULT] [hasThis] Void
System.Diagnost ics.StackTrace. CaptureStackTra ce(I4,Boolean,C lass
System.Threadin g.Thread,Class System.Exceptio n)
0x40bae1e0 0x799f11fc [DEFAULT] [hasThis] Void
System.Diagnost ics.StackTrace. .ctor(Class System.Exceptio n,Boolean)
0x40bae1ec 0x799ef21f [DEFAULT] String
System.Environm ent.GetStackTra ce(Class System.Exceptio n)
0x40bae248 0x16e32c14 [FRAME: InterceptorFram e] [DEFAULT] String
System.Environm ent.GetStackTra ce(Class System.Exceptio n)
0x40bae258 0x799f1b09 [DEFAULT] [hasThis] String
System.Exceptio n.get_StackTrac e()
0x40bae260 0x799f1a32 [DEFAULT] [hasThis] String System.Exceptio n.ToString()
0x40bae28c 0x16e32b54 [FRAME: InterceptorFram e] [DEFAULT] [hasThis] String
System.Exceptio n.ToString()
0x40bae29c 0x799fc50e [DEFAULT] [hasThis] String
System.Exceptio n.InternalToStr ing()
0x40bae578 0x791b33cc [FRAME: GCFrame]
0x40baefa4 0x791b33cc [FRAME: GCFrame]
0x40baf670 0x791b33cc [FRAME: NDirectMethodFr ameGeneric] [DEFAULT] String
<namespaceremov ed>.ttGetRteVar Variation(I4)
0x40baf680 0x40278218 [DEFAULT] [hasThis] String
<namespaceremov ed>.GetRteVarVa riation(I4)
at [+0x8] [+0x0]
0x40baf684 0x402781df [DEFAULT] [hasThis] String
<namespaceremov ed>.get_Variati on()
at [+0x1f] [+0x0]
<more stack trace after this but not that interesting>

Here is the native stack for thread 26. Look like the thread was trying to
allocate space (probably for the exception) and forced a call to GC.

ChildEBP RetAddr
40badb8c 7c822114 ntdll!KiFastSys temCallRet
40badb90 77e6711b ntdll!NtWaitFor MultipleObjects +0xc
40badc38 77e61075 kernel32!WaitFo rMultipleObject sEx+0x11a
40badc54 791f2ff8 kernel32!WaitFo rMultipleObject s+0x18
40bade8c 791f311c mscorsvr!Thread ::SysSuspendFor GC+0x248
40badea4 791f337d mscorsvr!GCHeap ::SuspendEE+0xc f
40badec0 791f5775 mscorsvr!GCHeap ::GarbageCollec tGeneration+0x1 3f
40badef0 791bd4ae mscorsvr!gc_hea p::allocate_mor e_space+0x181
40bae118 791b5411 mscorsvr!GCHeap ::Alloc+0x7b
40bae12c 791b93c3 mscorsvr!Alloc+ 0x3a
40bae14c 791b9411 mscorsvr!FastAl locateObject+0x 25
40bae1b8 799ef4fc mscorsvr!JIT_Ne wFast+0x2c
WARNING: Stack unwind information not available. Following frames may be
wrong.
40bae1cc 799f11fc mscorlib_799900 00+0x5f4fc
40bae1e0 799ef21f mscorlib_799900 00+0x611fc
40bae204 791d8504 mscorlib_799900 00+0x5f21f
40bae218 00000000 mscorsvr!DoDecl arativeSecurity +0x1a

I went looking for the garbage collection thread to see what it was up to.
I found 4 GC threads. They all look the same. Here is the native stack for
one of the GC threads:

2 Id: 2394.1910 Suspend: 1 Teb: 7ffdd000 Unfrozen
ChildEBP RetAddr Args to Child
WARNING: Stack unwind information not available. Following frames may be
wrong.
00daff70 77e6ba12 000000bc ffffffff 00000000 ntdll!KiFastSys temCallRet
00daff84 791f3206 000000bc ffffffff 00000000 kernel32!WaitFo rSingleObject+0 x12
00daffac 79224ac2 00000000 00daffec 77e66063
mscorsvr!gc_hea p::gc_thread_fu nction+0x2f
00daffb8 77e66063 00150448 00000000 00000000
mscorsvr!gc_hea p::gc_thread_st ub+0x1e
00daffec 00000000 79224aa4 00150448 00000000 kernel32!GetMod uleFileNameA+0x eb
Looks like the garbage collection is waiting for something to happen. Some
research I have done tells me the garbage collection has to suspend all
threads before doing its work and that garbage collection can not suspend a
thread if the PreEmptive GC is disabled. PreEmptive GC can be disabled if
the thread is calling unmanaged code. Looks like I have a classic deadlock:

1) garbage collector is waiting for all threads to suspend.
2) thread is waiting for garbage collector to finish.

I believe I know why the code is throwing NullReferenceEx ception and I am
fixing it.

My worry here is that this is a generic thing (A GC call is forced while
PreEmptive GC is disabled) that could happen and could still happen even if I
get rid of the NullReferenceEx ceptions.

Does anybody have any ideas or thoughts here? Have I found a bug/feature in
the .NET framework?

Oct 12 '06 #1
0 2747

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

Similar topics

1
6078
by: Robert Brown | last post by:
I have a deadlock that's happening on one oracle instance but cannot be reproduced on any other. It is always caused by the same SQL statement colliding with itself and only happens under very high load. The statement is DELETE from userlogins WHERE numlogins <= 0 the schema for the userlogins table is
0
1619
by: Alice | last post by:
Hello I have four multithread windows applications(vb.net) interacting and running on the same machine(windows 2000 with .net framework 1.0). All of them start a new thread each time Filewatcher's created or deleted event is fired. One of these application writes data into word documents also in multithread fashion. Sometimes the created and the deleted events of FileWatcher are not fired in one application - not the same one each time. Any...
8
9552
by: Javauser | last post by:
Hi there we are getting the following db2 error on executeBatch() method that inserts n rows on a table (where n is between 50 and 200). SQL0911N The current transaction has been rolled back because of a deadlock or timeout. Reason code "2". SQLSTATE=40001 errorCode : 911
3
7628
by: Nigel Robbins | last post by:
Hi There, I'm getting a deadlock when I have two clients running the following statement. DELETE FROM intermediate.file_os_details WHERE file_uid = ? AND obj_uid There is a compound index on file_uid / obj_uid. The isolation level is UR and I have set DB2_RR_TO_RS=YES. Any thoughts why I'm getting the deadlock ?
1
4243
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here. From the log it looks like the problem happens when 2 threads insert 1 record each in the same table and then try to aquire a NS (Next Key Share) lock on the record inserterd by the other thread. Thanks Rohit
6
3773
by: Todd McNeill | last post by:
Hi- We ran into some very strange deadlocks this AM, and I was hoping to get some insight. We were running a REORGCHK on a database, and started getting deadlocks. What is curious is that according to the deadlock event monitor, the deadlock was between the REORGCHK process and another client attempting a SQL execution, and the Prepare was requesting an Exclusive lock. Is that normal? Maybe I'm reading the monitor output...
15
10005
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried) 3-4 times and give up if after that it's still in deadlock. I'm very sure that many experienced people out there already deal with this issue somehow. Is there an alternative to it? Thanks for your comments and suggestions.
0
1402
by: Gordon Cone | last post by:
I am currently debugging a deadlock in a multithread C# application. It makes lots of calls to legacy unmanaged code. The application runs on windows sever 2003 and uses the sever version of the CLR. The application runs on ..NET 1.1 SP1. When the deadlock happens the process is using 0 CPU. I was able to collect crash dumps and have been trying to make sense out of them using windbg.
0
11704
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.