Skip to content

Commit

Permalink
Fix NPE caused by the race condition (apache#2973)
Browse files Browse the repository at this point in the history
  • Loading branch information
massakam authored and nkurihar committed Nov 13, 2018
1 parent 915411b commit 9ecfb7d
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2609,16 +2609,18 @@ public void activateCursor(ManagedCursor cursor) {
}

public void deactivateCursor(ManagedCursor cursor) {
if (activeCursors.get(cursor.getName()) != null) {
activeCursors.removeCursor(cursor.getName());
if (activeCursors.isEmpty()) {
// cleanup cache if there is no active subscription
entryCache.clear();
} else {
// if removed subscription was the slowest subscription : update cursor and let it clear cache: till
// new slowest-cursor's read-position
discardEntriesFromCache((ManagedCursorImpl) activeCursors.getSlowestReader(),
getPreviousPosition((PositionImpl) activeCursors.getSlowestReader().getReadPosition()));
synchronized (activeCursors) {
if (activeCursors.get(cursor.getName()) != null) {
activeCursors.removeCursor(cursor.getName());
if (activeCursors.isEmpty()) {
// cleanup cache if there is no active subscription
entryCache.clear();
} else {
// if removed subscription was the slowest subscription : update cursor and let it clear cache:
// till new slowest-cursor's read-position
discardEntriesFromCache((ManagedCursorImpl) activeCursors.getSlowestReader(),
getPreviousPosition((PositionImpl) activeCursors.getSlowestReader().getReadPosition()));
}
}
}
}
Expand Down

0 comments on commit 9ecfb7d

Please sign in to comment.