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

FISH-5723 Fixes WebappClassloader memory-leak issue by removing JAXRS… #5111

Merged
merged 1 commit into from
Aug 16, 2022
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
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,6 +17,7 @@

package org.glassfish.jersey.internal.util.collection;

import java.util.Enumeration;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -107,6 +109,15 @@ public void clear() {
cache.clear();
}

/**
* Get the cache keys
*
* @return
*/
public Enumeration<K> keys() {
return cache.keys();
}

/**
* Returns true if the key has already been cached.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -59,12 +59,16 @@
import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.inject.spi.ProcessInjectionTarget;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;

import org.glassfish.jersey.ext.cdi1x.internal.spi.InjectionManagerInjectedTarget;
import org.glassfish.jersey.ext.cdi1x.internal.spi.InjectionManagerStore;
Expand Down Expand Up @@ -857,6 +861,11 @@ private void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanD
);
}

@SuppressWarnings("unused")
private void beforeShutDown(@Observes final BeforeShutdown beforeShutdown, final BeanManager beanManager) {
runtimeSpecifics.clearJaxRsResource(Thread.currentThread().getContextClassLoader());
}

/**
* Add a predicate to test HK2 dependency to create a CDI bridge bean to HK2 for it.
* @param predicate to test whether given class is a HK2 dependency.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -20,6 +21,7 @@
import javax.enterprise.inject.spi.AnnotatedType;
import javax.ws.rs.core.Context;
import java.lang.annotation.Annotation;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -59,4 +61,9 @@ public boolean isAcceptableResource(Class<?> resource) {
public boolean isJaxRsResource(Class<?> resource) {
return false;
}

@Override
public void clearJaxRsResource(ClassLoader loader) {
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -34,4 +35,6 @@ interface CdiComponentProviderRuntimeSpecifics {
boolean isAcceptableResource(Class<?> resource);

boolean isJaxRsResource(Class<?> resource);

void clearJaxRsResource(ClassLoader loader);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Payara Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -48,6 +49,7 @@
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.util.Enumeration;

/**
* Server side runtime CDI ComponentProvider specific implementation.
Expand Down Expand Up @@ -225,6 +227,17 @@ public boolean isJaxRsResource(Class<?> resource) {
return jaxRsResourceCache.apply(resource);
}

@Override
public void clearJaxRsResource(ClassLoader loader) {
Enumeration<Class<?>> keys = jaxRsResourceCache.keys();
while (keys.hasMoreElements()) {
Class<?> key = keys.nextElement();
if (key.getClassLoader() == loader) {
jaxRsResourceCache.remove(key);
}
}
}

@Override
public boolean containsJaxRsParameterizedCtor(final AnnotatedType annotatedType) {
return CdiComponentProvider
Expand Down