Hi all,
I was wondering if anyone here had experience diagnosing some SQL Server deadlock I have recently run into, or if anyone has encountered this problem before on other databases.
The situation I have run into is that of a SELECT query blocking an UPDATE query, and the UPDATE blocking the SELECT. Now, it makes sense that the UPDATE would block the select (since it is a part of a transaction). The transaction isolation level is set to read committed and according to the activity monitor the UPDATE has acquired an exclusive lock (LCK_M_X). However I do not understand why the UPDATE is waiting on a SELECT. The SELECT does not hold any locks and its wait type is ASYNC_NETWORK_IO. Now, I looked this wait type up and it suggests that this is when the database is waiting on the client to read data. However what I do not understand is why or how this would block the UPDATE.
My understanding (which is failing me at this point I can see) is that when this scenario arises the UPDATE should finish (commit its transaction), releasing its exclusive lock on that row in the process, allowing the SELECT to proceed and read the committed data.
Luckily, this scenario seems to be fairly reproducible, which has allowed me to capture a trace of the statements leading up to the deadlock, as well as having the ability to fire up the activity monitor and look at what exactly is going on and what is blocking what when it happens. I have a screenshot of the activity monitor available as well as the trace file if anyone is interested.
Has anyone encountered this sort of thing before? Does anyone have any suggestions on how I could possibly go about debugging/diagnosing this sort of thing? The UPDATE and SELECT are coming from two different threads running in a Java webapp. My current idea is to attempt to diagnose the problem outside of the Java application (essentially distill the problem down to what exactly is happening) and then modify the Java to avoid/remedy this situation.
I was wondering if anyone here had experience diagnosing some SQL Server deadlock I have recently run into, or if anyone has encountered this problem before on other databases.
The situation I have run into is that of a SELECT query blocking an UPDATE query, and the UPDATE blocking the SELECT. Now, it makes sense that the UPDATE would block the select (since it is a part of a transaction). The transaction isolation level is set to read committed and according to the activity monitor the UPDATE has acquired an exclusive lock (LCK_M_X). However I do not understand why the UPDATE is waiting on a SELECT. The SELECT does not hold any locks and its wait type is ASYNC_NETWORK_IO. Now, I looked this wait type up and it suggests that this is when the database is waiting on the client to read data. However what I do not understand is why or how this would block the UPDATE.
My understanding (which is failing me at this point I can see) is that when this scenario arises the UPDATE should finish (commit its transaction), releasing its exclusive lock on that row in the process, allowing the SELECT to proceed and read the committed data.
Luckily, this scenario seems to be fairly reproducible, which has allowed me to capture a trace of the statements leading up to the deadlock, as well as having the ability to fire up the activity monitor and look at what exactly is going on and what is blocking what when it happens. I have a screenshot of the activity monitor available as well as the trace file if anyone is interested.
Has anyone encountered this sort of thing before? Does anyone have any suggestions on how I could possibly go about debugging/diagnosing this sort of thing? The UPDATE and SELECT are coming from two different threads running in a Java webapp. My current idea is to attempt to diagnose the problem outside of the Java application (essentially distill the problem down to what exactly is happening) and then modify the Java to avoid/remedy this situation.