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

Classloader leak with Throwable in static fields #1872

Closed
fsgonz opened this issue Aug 30, 2019 · 2 comments
Closed

Classloader leak with Throwable in static fields #1872

fsgonz opened this issue Aug 30, 2019 · 2 comments
Labels
type/enhancement A general enhancement

Comments

@fsgonz
Copy link

fsgonz commented Aug 30, 2019

In dynamic classloader environments, the use of Throwable in static fields may cause a classloader leak in the backtrace field. This field is set in runtime at native code with an array that are instances of Class. This may cause a Classloader which should be disposed to be retained.

In other projects, an error without a writable stacktrace was used for this cases.

I've opened a PR for this:
#1871

Let me know.

Thanks!

@simonbasle
Copy link
Member

reference of a similar issue in the JDK: https://bugs.openjdk.java.net/browse/JDK-8146961

@simonbasle
Copy link
Member

simonbasle commented Sep 2, 2019

Thanks for reporting this! IntelliJ Structural Search reveals a total of 4 static fields that have a type that extends Throwable:

  • Throwable Exceptions.TERMINATED (covered in your PR)
  • RejectedExecutionException Exceptions.REJECTED_EXECUTION
  • RejectedExecutionException Exceptions.NOT_TIME_CAPABLE_REJECTED_EXECUTION
  • AlertException.INSTANCE (already avoiding stacktrace filling)

source search template: static $Type$ $Variable$ = $Init$; with text constraint on Type: Throwable is withinHierarchy

@simonbasle simonbasle added the type/enhancement A general enhancement label Sep 2, 2019
@simonbasle simonbasle added this to the 3.2.12.RELEASE milestone Sep 2, 2019
simonbasle added a commit that referenced this issue Sep 2, 2019
When the stacktrace of a `Throwable` is filled, the JVM transparently
adds a `backtrace` field that references classes from the stacktrace.
In multi-classloader environments, this can lead to leaks when the
`Throwable` (of subclass of) is static.

This commit changes the few occurrences of static exceptions in Reactor
so that they each use a variant that doesn't fill the stack trace.

TERMINATED uses a general-purpose StaticThrowable which means that it
can reference the super constructor with boolean flags disabling
exception suppression and stack trace filling, without having to
override the fillInStackTrace method.

Reviewed-in: #1876
simonbasle added a commit that referenced this issue Sep 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants