diff options
author | broneill <bronee@gmail.com> | 2015-04-12 08:02:29 -0700 |
---|---|---|
committer | broneill <bronee@gmail.com> | 2015-04-12 08:10:38 -0700 |
commit | 291ac5d88b79cae83ab812ff866f4364e62ef49f (patch) | |
tree | 61d291b82f0f911c76289e4082ec8a71d293d317 /src | |
parent | f14d8fc7de0f49dc66d5a2871d5141f5c679a2b2 (diff) |
Prevent deadlock between cursor close and TransactionScope cleanup.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/amazon/carbonado/raw/RawCursor.java | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/src/main/java/com/amazon/carbonado/raw/RawCursor.java b/src/main/java/com/amazon/carbonado/raw/RawCursor.java index 4b7ef09..b3dbb0b 100644 --- a/src/main/java/com/amazon/carbonado/raw/RawCursor.java +++ b/src/main/java/com/amazon/carbonado/raw/RawCursor.java @@ -111,8 +111,8 @@ public abstract class RawCursor<S> extends AbstractCursor<S> { }
public boolean hasNext() throws FetchException {
- mLock.lock();
try {
+ mLock.lock();
try {
switch (mState) {
case UNINITIALIZED:
@@ -137,47 +137,47 @@ public abstract class RawCursor<S> extends AbstractCursor<S> { case HAS_NEXT:
return true;
}
- } catch (FetchException e) {
- // Auto-close in response to FetchException.
- try {
- close();
- } catch (FetchException e2) {
- // Ignore.
- }
- throw e;
+ } finally {
+ mLock.unlock();
}
-
- // Reached the end naturally, so close.
- close();
- } finally {
- mLock.unlock();
+ } catch (FetchException e) {
+ // Auto-close in response to FetchException.
+ try {
+ close();
+ } catch (FetchException e2) {
+ // Ignore.
+ }
+ throw e;
}
+ // Reached the end naturally, so close.
+ close();
+
return false;
}
public S next() throws FetchException, NoSuchElementException {
- mLock.lock();
try {
- if (!hasNext()) {
- handleNoSuchElement();
- throw new NoSuchElementException();
- }
+ mLock.lock();
try {
+ if (!hasNext()) {
+ handleNoSuchElement();
+ throw new NoSuchElementException();
+ }
S obj = instantiateCurrent();
mState = TRY_NEXT;
return obj;
- } catch (FetchException e) {
- // Auto-close in response to FetchException.
- try {
- close();
- } catch (FetchException e2) {
- // Ignore.
- }
- throw e;
+ } finally {
+ mLock.unlock();
}
- } finally {
- mLock.unlock();
+ } catch (FetchException e) {
+ // Auto-close in response to FetchException.
+ try {
+ close();
+ } catch (FetchException e2) {
+ // Ignore.
+ }
+ throw e;
}
}
@@ -190,38 +190,38 @@ public abstract class RawCursor<S> extends AbstractCursor<S> { return 0;
}
- mLock.lock();
try {
int actual = 0;
- if (hasNext()) {
- try {
+ mLock.lock();
+ try {
+ if (hasNext()) {
actual += mReverse ? toBoundedPrevious(amount) : toBoundedNext(amount);
- } catch (FetchException e) {
- // Auto-close in response to FetchException.
- try {
- close();
- } catch (FetchException e2) {
- // Ignore.
- }
- throw e;
- }
- if (actual >= amount) {
- return actual;
+ if (actual >= amount) {
+ return actual;
+ }
+ mState = TRY_NEXT;
+ // Since state was HAS_NEXT and is forced into TRY_NEXT, actual
+ // amount skipped is effectively one more.
+ actual++;
}
- mState = TRY_NEXT;
- // Since state was HAS_NEXT and is forced into TRY_NEXT, actual
- // amount skipped is effectively one more.
- actual++;
+ } finally {
+ mLock.unlock();
}
// Reached the end naturally, so close.
close();
return actual;
- } finally {
- mLock.unlock();
+ } catch (FetchException e) {
+ // Auto-close in response to FetchException.
+ try {
+ close();
+ } catch (FetchException e2) {
+ // Ignore.
+ }
+ throw e;
}
}
|