-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid ClassLoader leaks caused by SharedTimer
Avoid ClassLoader leaks caused by the TimerThread started by SharedTimer inheriting the contextClassLoader of the currently executing thread and the AccessControlContext containing ProtectionDomains with calling code. closes #664
- Loading branch information
Showing
5 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
pgjdbc/src/test/java/org/postgresql/test/util/SharedTimerClassLoaderLeakTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2016, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.test.util; | ||
|
||
import org.postgresql.Driver; | ||
|
||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import se.jiderhamn.classloader.PackagesLoadedOutsideClassLoader; | ||
import se.jiderhamn.classloader.leak.JUnitClassloaderRunner; | ||
import se.jiderhamn.classloader.leak.Leaks; | ||
|
||
/** | ||
* Test case that verifies that the use of {@link org.postgresql.util.SharedTimer} within | ||
* {@link org.postgresql.Driver} does not cause ClassLoader leaks | ||
* @author Mattias Jiderhamn | ||
*/ | ||
@RunWith(JUnitClassloaderRunner.class) | ||
@PackagesLoadedOutsideClassLoader(packages = "org.postgresql", addToDefaults = true) | ||
public class SharedTimerClassLoaderLeakTest { | ||
|
||
/** Starting a {@link org.postgresql.util.SharedTimer} should not cause ClassLoader leaks */ | ||
@Leaks(false) | ||
@Test | ||
public void sharedTimerDoesNotCauseLeak() { | ||
Driver.getSharedTimer().getTimer(); // Start timer | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
Driver.getSharedTimer().releaseTimer(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters