Skip to content

Commit

Permalink
WFLY-5937 Potential StackOverflowError during distributed session inv…
Browse files Browse the repository at this point in the history
…alidation
  • Loading branch information
pferraro committed Jan 5, 2016
1 parent e88acc6 commit df44f89
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Expand Up @@ -32,4 +32,13 @@ public interface Remover<K> {
* @return true, if the entry was removed.
*/
boolean remove(K id);

/**
* Like {@link #remove(Object)}, but does not notify listeners.
* @param id the cache entry identifier.
* @return true, if the entry was removed.
*/
default boolean purge(K id) {
return this.remove(id);
}
}
Expand Up @@ -65,7 +65,7 @@ public Map.Entry<InfinispanSessionMetaData<L>, V> findValue(String id) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
// Purge obsolete meta data
this.metaDataFactory.remove(id);
this.metaDataFactory.purge(id);
}
return null;
}
Expand All @@ -79,7 +79,7 @@ public Map.Entry<InfinispanSessionMetaData<L>, V> tryValue(String id) {
return new SimpleImmutableEntry<>(metaDataValue, attributesValue);
}
// Purge obsolete meta data
this.metaDataFactory.remove(id);
this.metaDataFactory.purge(id);
}
return null;
}
Expand Down
Expand Up @@ -73,29 +73,28 @@ public InfinispanSessionMetaData<L> tryValue(String id) {
}

private InfinispanSessionMetaData<L> getValue(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) {
SessionCreationMetaDataKey creationMetaDataKey = new SessionCreationMetaDataKey(id);
SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id);
// Workaround for ISPN-6007
if (this.lockOnRead) {
try {
// lock() can only be called within an active tx context
if (this.transactional && (creationMetaDataCache.getAdvancedCache().getTransactionManager().getStatus() == Status.STATUS_ACTIVE)) {
if (!creationMetaDataCache.getAdvancedCache().lock(creationMetaDataKey)) {
if (!creationMetaDataCache.getAdvancedCache().lock(key)) {
return null;
}
}
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
SessionCreationMetaDataEntry<L> creationMetaDataEntry = creationMetaDataCache.get(creationMetaDataKey);
SessionCreationMetaDataEntry<L> creationMetaDataEntry = creationMetaDataCache.get(key);
if (creationMetaDataEntry != null) {
SessionAccessMetaDataKey accessMetaDataKey = new SessionAccessMetaDataKey(id);
SessionAccessMetaData accessMetaData = this.accessMetaDataCache.get(accessMetaDataKey);
SessionAccessMetaData accessMetaData = this.accessMetaDataCache.get(new SessionAccessMetaDataKey(id));
if (accessMetaData != null) {
return new InfinispanSessionMetaData<>(creationMetaDataEntry.getMetaData(), accessMetaData, creationMetaDataEntry.getLocalContext());
}
// Purge orphaned entry, making sure not to trigger cache listener
this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.SKIP_LISTENER_NOTIFICATION).remove(creationMetaDataKey);
creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES, Flag.SKIP_LISTENER_NOTIFICATION).remove(key);
}
return null;
}
Expand All @@ -120,9 +119,18 @@ public ImmutableSessionMetaData createImmutableSessionMetaData(String id, Infini

@Override
public boolean remove(String id) {
return this.remove(id, this.creationMetaDataCache);
}

@Override
public boolean purge(String id) {
return this.remove(id, this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.SKIP_LISTENER_NOTIFICATION));
}

private boolean remove(String id, Cache<SessionCreationMetaDataKey, SessionCreationMetaDataEntry<L>> creationMetaDataCache) {
SessionCreationMetaDataKey key = new SessionCreationMetaDataKey(id);
if (this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) {
this.creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionCreationMetaDataKey(id));
if (creationMetaDataCache.getAdvancedCache().withFlags(Flag.ZERO_LOCK_ACQUISITION_TIMEOUT, Flag.FAIL_SILENTLY).lock(key)) {
creationMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(key);
this.accessMetaDataCache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).remove(new SessionAccessMetaDataKey(id));
return true;
}
Expand Down
Expand Up @@ -92,8 +92,6 @@ public void findValue() {
assertNotNull(existingSessionResult);
assertSame(metaData, existingSessionResult.getKey());
assertSame(attributes, existingSessionResult.getValue());

verify(this.metaDataFactory).remove(missingAttributesSessionId);
}

@Test
Expand Down

0 comments on commit df44f89

Please sign in to comment.