Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-2931 Resolved Memory Leak - Payara4 #3068

Merged
merged 1 commit into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2018] Payara Foundation and/or affiliates

package org.apache.catalina.session;

Expand All @@ -78,8 +79,8 @@
import java.io.ObjectOutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -140,7 +141,7 @@ public final class FileStore extends StoreBase {
* Our write-through cache of session objects
* HERCULES: addition
*/
private Hashtable<String, Session> sessions = new Hashtable<String, Session>();
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();


// ------------------------------------------------------------- Properties
Expand Down Expand Up @@ -346,13 +347,8 @@ public Session load(String id)
}

try {
StandardSession session =
StandardSession.deserialize(ois, manager);
session.setManager(manager);
//HERCULES: addition
// Put it in the cache
sessions.put(session.getIdInternal(), session);
//HERCULES: addition
StandardSession session = StandardSession.deserialize(ois, manager);
session.setManager(manager);
return (session);
} finally {
// Close the input stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2016] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]

package org.apache.catalina.session;

Expand Down Expand Up @@ -659,11 +659,20 @@ protected void processInvalidatedSessions() {
* aren't too many active sessions, or if there is no limit,
* a session is created or retrieved from the recycled pool.
*
* @return the new session
* @exception IllegalStateException if a new session cannot be
* instantiated for any reason
*/
@Override
public Session createSession() {

if (((maxActiveSessions >= 0) && (sessions.size() >= maxActiveSessions))) {
if (store == null){
//too many active sessions and no store
throw new IllegalStateException(rb.getString(LogFacade.CREATE_SESSION_EXCEPTION));
}
//swap out active sessions to store
processMaxActiveSwaps();
}
return (super.createSession());

}
Expand All @@ -686,8 +695,16 @@ public Session createSession() {
* @return the new session, or <code>null</code> if a session with the
* requested id already exists
*/
@Override
public Session createSession(String sessionId) {

if (((maxActiveSessions >= 0) && (sessions.size() >= maxActiveSessions))) {
if (store == null){
//too many active sessions and no store
throw new IllegalStateException(rb.getString(LogFacade.CREATE_SESSION_EXCEPTION));
}
//swap out active sessions to store
processMaxActiveSwaps();
}
return (super.createSession(sessionId));

}
Expand Down Expand Up @@ -1336,11 +1353,11 @@ protected void processMaxActiveSwaps() {
Session sessions[] = findSessions();

// FIXME: Smarter algorithm (LRU)
if (getMaxActiveSessions() > sessions.length)
if (getMaxActiveSessions() >= sessions.length)
return;

if(log.isLoggable(Level.FINE)) {
log.log(Level.FINE, LogFacade.TOO_MANY_ACTIVE_SESSION, Integer.valueOf(sessions.length));
log.log(Level.FINE, LogFacade.TOO_MANY_ACTIVE_SESSION, sessions.length);
}
int toswap = sessions.length - getMaxActiveSessions();
long timeNow = System.currentTimeMillis();
Expand Down