Should you request lockout timeouts in .NET?

In Release It! Michael Nigard explains that many catastrophic system failures are often caused by a number of errors. For example, blocking two threads. Now there are even fewer threads in the thread pool, so load on other threads increases, increasing the likelihood of deadlocks. Suddenly, the server does not respond at all, because the thread pool is exhausted, which leads to the fact that the load balancer redirects traffic to other servers (they all work with the same code), which increases the likelihood of deadlocks. Suddenly the whole farm is offline.

Most RDBMS servers detect deadlocks and determine "failure" (one transaction is aborted, the other can continue). In contrast, in C # the lock statement will wait indefinitely for the lock to be received.

However, you can call Monitor.TryEnter (lockObject, TimeSpan) to request a lock or timeout. It returns false if the timeout expires and the lock cannot be obtained. Some of them wrapped this with statements to preserve good syntax.

So my question is: do you always get locks using timeouts or not? And what problems do timeouts create compared to a deadlock scenario?

+5
source share
4 answers

I usually use timeouts. The biggest problem here is that if the timeout is reached, the operation request will be aborted. This is obviously preferable to deadlock. There is a big problem: if the operation is critical and you start interrupting because something else has come to a standstill, if your design doesn’t sound, you can end up causing a farm problem described using this method (albeit softer: your application will no longer work, but you have not lost control).

, , , , .

+5

, . . - , , , . , , , .

+1

, ? , . , . ? . - , , , .

+1

, . , (. Linux lockdep).

Therefore, always trying to block does not make sense. It depends on the circumstances.

0
source

All Articles