[ 
https://issues.apache.org/jira/browse/CASSANDRA-19763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17866834#comment-17866834
 ] 

Michael Semb Wever commented on CASSANDRA-19763:
------------------------------------------------

What happens if the lock() acquires the lock but still throws some other 
exception, like OOM …? Are we left with a stalelock and a non-functioning 
system ? Are there situations where we might intentionally choose to deal with 
catching a lock() exception as well as catching the unlock() exception for the 
guarantee of leaving the system correct ? Would this risk  a failed lock() 
attempt then unlocking someone else's lock potentially leading to unsafe 
concurrent access …?

> Reentrant locks should always be locked outside of a try block
> --------------------------------------------------------------
>
>                 Key: CASSANDRA-19763
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-19763
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Ling Mao
>            Assignee: Ling Mao
>            Priority: Low
>             Fix For: 5.x
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> {color:#172b4d}Acquiring the lock should always be done before the try block 
> so that the finally clause to unlock will never execute unless the lock is 
> acquired. More info:{color}
>  
> {code:java}
> https://stackoverflow.com/questions/31058681/java-locking-structure-best-pattern
> https://issues.apache.org/jira/browse/AMQ-9202
> {code}
>  
> Unfortunately, there are no ready-made rules in Checkstyle, FindBugs, or 
> SpotBugs for this type of violation checking. I use "IDEA inspection" to 
> identify all such violations.
> {code:java}
> IDEA Code -> Analyze Code -> Run Inspection by Name(Lock acquired but not 
> safely unlocked) ---> Whole project{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to