rspec/rules/S2222/why-dotnet.adoc
2023-06-07 12:01:33 +02:00

19 lines
1.1 KiB
Plaintext

== Why is this an issue?
To prevent potential https://en.wikipedia.org/wiki/Deadlock[deadlocks] in an application, it is crucial to release any locks that are acquired within a method along all possible execution paths.
Failing to release locks properly can lead to potential deadlocks, where the lock might not be released, causing issues in the application.
This rule specifically focuses on tracking the following types from the `System.Threading` namespace:
* https://learn.microsoft.com/en-us/dotnet/api/system.threading.monitor[`Monitor`]
* https://learn.microsoft.com/en-us/dotnet/api/system.threading.mutex[`Mutex`]
* https://learn.microsoft.com/en-us/dotnet/api/system.threading.readerwriterlock[`ReaderWriterLock`]
* https://learn.microsoft.com/en-us/dotnet/api/system.threading.readerwriterlockslim[`ReaderWriterLockSlim`]
* https://learn.microsoft.com/en-us/dotnet/api/system.threading.spinlock[`SpinLock` ]
An issue is reported when a lock is acquired within a method but not released on all paths.
=== Exceptions
If the lock is never released within the method, no issue is raised, assuming that the callers will handle the release.