ehcache keySet timed out when using getKeysWithExpiryCheck() method
<p>I am using ehcache to control user sessions, every once in a while I see this error in the log upon users login.</p>

<pre><code>net.sf.ehcache.constructs.nonstop.NonStopCacheException: keySet timed out
    at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:103)
    at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator$1.performClusterOperationTimedOut(NonStopCacheKeySet.java:96)
    at net.sf.ehcache.constructs.nonstop.store.ExecutorServiceStore.executeClusterOperation(ExecutorServiceStore.java:1187)
    at net.sf.ehcache.constructs.nonstop.store.NonstopStoreImpl.executeClusterOperation(NonstopStoreImpl.java:704)
    at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet$NonStopCacheKeySetIterator.&lt;init&gt;(NonStopCacheKeySet.java:96)
    at net.sf.ehcache.constructs.nonstop.concurrency.NonStopCacheKeySet.iterator(NonStopCacheKeySet.java:56)
    at net.sf.ehcache.Cache.getKeysWithExpiryCheck(v.java:1906)
...
</code></pre>

<p>The <a href="http://www.ehcache.org/apidocs/2.9/net/sf/ehcache/Cache.html#getKeysWithExpiryCheck()" rel="nofollow noreferrer">official ehcache doucmentation</a> says: "Consider whether your usage requires checking for expired keys. Because this method takes so long, depending on cache settings,...". </p>

<p>So I am not really sure what timeout in the ecache.xml to increase to stop this error even though 20000 ms seems like more than enough to me, because the documentation also mentioned that the time taken is approximately 200ms per 1000 entries. </p>

<p>This is the used ehcache.xml.</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;ehcache name="RelianceCache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"&gt;


    &lt;cache name="READ_USERS_CACHE" maxElementsInMemory="0" eternal="true" overflowToDisk="false"&gt;
        &lt;terracotta clustered="true" valueMode="serialization"  consistency="strong"&gt;
            &lt;nonstop immediateTimeout="false" timeoutMillis="20000"&gt;
                &lt;timeoutBehavior type="exception" /&gt;
            &lt;/nonstop&gt;
        &lt;/terracotta&gt;
    &lt;/cache&gt;


    &lt;terracottaConfig url="TSA_SERVERS:TSA_PORT" rejoin="true" /&gt;
&lt;/ehcache&gt;
</code></pre>

<p>Edit:
See <a href="http://svn.terracotta.org/svn/ehcache/tags/ehcache-core-2.5.7/src/main/java/net/sf/ehcache/constructs/nonstop/concurrency/NonStopCacheKeySet.java" rel="nofollow noreferrer">the NonStopCacheKeySet implementation</a>, the error is being thrown in the method <code>NonStopCacheKeySetIterator</code>.</p>