[
https://issues.apache.org/jira/browse/NIFI-526?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14503412#comment-14503412
]
Mark Payne commented on NIFI-526:
---------------------------------
Mike,
Let's say Thread-1 comes in and gets the readLock and determines that
"timeToPersist < System.currentTimeMillis()" is true. It relinquishes readLock.
Thread-2 comes in, gets readLock, also determines that it's true. It then
relinquishes readLock, obtains writeLock, does its business, and relinquishes
writeLock.
Thread-1 then gets writeLock. Since Thread-2 has updated the "timeToPersist"
variable, Thread-1 determines "timeToPersist < System.currentTimeMillis()" is
false. It exits this part of the code without ever unlocking writeLock.
But regardless, the code obtains writeLock, and then unlocks it only if a
condition is met -- so even if it was impossible for that that condition not to
be met it's a really bad practice and needs to be addressed.
Thanks
-Mark
> GetHTTP may not release writeLock
> ---------------------------------
>
> Key: NIFI-526
> URL: https://issues.apache.org/jira/browse/NIFI-526
> Project: Apache NiFi
> Issue Type: Bug
> Components: Extensions
> Affects Versions: 0.0.2
> Reporter: Mark Latimer
> Priority: Minor
> Labels: beginner, newbie
> Fix For: 0.1.0
>
>
> GetHTTP onTrigger process contains a path that will obtain and not release
> the writeLock.
> This happens if enough time elapses between the first and second check of
> timeToPersist.
> Also the readLock locked and unlocked with no meaningful work in between.
> {code:title=GetHTTP.java|borderStyle=solid}
> if ((etag != null || lastModified != null) &&
> readLock.tryLock()) {
> try {
> //first check of timeToPersist against current time
> if (timeToPersist < System.currentTimeMillis()) {
> readLock.unlock();
> //obtain writeLock
> writeLock.lock();
> //check time to persist again, this result may be
> different
> //if the result is different because enough time
> has elapsed the lock is not released
> if (timeToPersist < System.currentTimeMillis()) {
> try {
>
> ...
>
> } finally {
> readLock.lock();
> //release writeLock only if the second
> check of timeToPresist is before now.
> writeLock.unlock();
> }
> }
> }
> } finally {
> readLock.unlock();
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)