Monday, March 26, 2012

strange error - deadlock

HI Y'all,

I get following error and i'm kinda worried:

Transaction (Process ID 194) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Anyone ever saw this?

Thanks

Hi,

I saw this sometimes in our environment. What happened is the following: if you have 5 (the number doesn't implicate anything, it could be 2) web applications accessing the same database table at the same time and for some reason one of them is not be able to commit the process, as such all the other applications will be waiting for this process to commit which creates a dead lock in a sense all the applications are waiting for this process and the process it self is waiting to be completed. The only solution in this case is that the database server will stop the deadlock process.

Regards


It appears that the n number of transactions you are using, one of them is blocking operations on the other.
Transactions can be notorious as some of the tend to lock the whole table which is why any other processes trying to access data from that (locked) table it has to wait until the lock is released.

To solve this analyse all the points in your source code which use transactions. Go through each one and make sure the Transaction scope it as small as possible (Small meaning as little work is done there as possible).
This could mean you are declaring variables, doing some complex calculations etc. If you could move all of this outside the scope of the transaction you will end up avoiding this issue. If the transactions are not in the code but in stored proc do the same thing with the SQL scripts. There is a possibility that the table does not have sufficient index, add some indexes to speed up the queries.

Also if SQL Server is being used that would mean there is a possibility that the version you are using has connection limits and hence you app is waiting for a conn to be available, check the documentation of your SQL Server version for this.

Goodluck

0 comments:

Post a Comment