From 913ef1a39a27d06a48239738421cd982ef6edee9 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 6 Jan 2016 11:22:18 +1100 Subject: [PATCH] 485064 HashSessionManager leaks ScheduledExecutorScheduler with reference to un-deployed webapp --- .../server/session/HashSessionManager.java | 8 +++++-- .../session/HashSessionManagerTest.java | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java index a54cac0931a..68e5227e947 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashSessionManager.java @@ -182,8 +182,13 @@ public class HashSessionManager extends AbstractSessionManager _saveTask=null; if (_task!=null) _task.cancel(); - + _task=null; + + //if we're managing our own timer, remove it + if (isManaged(_timer)) + removeBean(_timer); + _timer=null; } @@ -192,7 +197,6 @@ public class HashSessionManager extends AbstractSessionManager super.doStop(); _sessions.clear(); - } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/HashSessionManagerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/HashSessionManagerTest.java index c1ad7da1aac..d776f409b75 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/HashSessionManagerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/HashSessionManagerTest.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.toolchain.test.FS; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.thread.Scheduler; import org.junit.Assert; import org.junit.Test; @@ -80,7 +81,25 @@ public class HashSessionManagerTest Server server = new Server(); SessionHandler handler = new SessionHandler(); handler.setServer(server); - HashSessionManager manager = new HashSessionManager(); + HashSessionManager manager = new HashSessionManager() + { + @Override + public void doStart() throws Exception + { + super.doStart(); + Scheduler timerBean = getBean(Scheduler.class); + Assert.assertNotNull(timerBean); + } + + @Override + public void doStop() throws Exception + { + super.doStop(); + Scheduler timerBean = getBean(Scheduler.class); + Assert.assertNull(timerBean); + } + + }; manager.setStoreDirectory(testDir); manager.setMaxInactiveInterval(5); Assert.assertTrue(testDir.exists());