Fix NPE caused by the race condition
@@ -2609,19 +2609,21 @@ public class ManagedLedgerImpl implements ManagedLedger, CreateCallback {
}
public void deactivateCursor(ManagedCursor cursor) {
+ 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
+ // 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()));
}
}
}
+ }
public boolean isCursorActive(ManagedCursor cursor) {
return cursor.isDurable() && activeCursors.get(cursor.getName()) != null;
