Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Jan Bartel 2020-12-24 15:54:48 +01:00
commit 84cff978ee
7 changed files with 23 additions and 205 deletions

View File

@ -33,15 +33,12 @@ module org.eclipse.jetty.util
// Standard Jetty Logging now.
requires org.slf4j;
// Only required if using DriverManagerLeakPreventer.
requires static java.sql;
// Only required if using AppContextLeakPreventer/AWTLeakPreventer.
requires static java.desktop;
// Only required if using JavaUtilLog.
requires static java.logging;
// Only required if using DriverManagerLeakPreventer.
requires static java.sql;
// Only required if using DOMLeakPreventer.
requires static java.xml;
uses CredentialProvider;
}

View File

@ -1,45 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.preventers;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* DOMLeakPreventer
*
* See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6916498
*
* Prevent the RuntimeException that is a static member of AbstractDOMParser
* from pinning a webapp classloader by causing it to be set here by a non-webapp classloader.
*
* Note that according to the bug report, a heap dump may not identify the GCRoot, making
* it difficult to identify the cause of the leak.
*/
public class DOMLeakPreventer extends AbstractLeakPreventer
{
@Override
public void prevent(ClassLoader loader)
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try
{
factory.newDocumentBuilder();
}
catch (Exception e)
{
LOG.warn("Unable to ping document builder", e);
}
}
}

View File

@ -1,39 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.preventers;
/**
* Java2DLeakPreventer
*
* Prevent pinning of webapp classloader by pre-loading sun.java2d.Disposer class
* before webapp classloaders are created.
*
* See https://issues.apache.org/bugzilla/show_bug.cgi?id=51687
*/
public class Java2DLeakPreventer extends AbstractLeakPreventer
{
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("sun.java2d.Disposer", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.trace("IGNORED", e);
}
}
}

View File

@ -1,41 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.preventers;
/**
* LDAPLeakPreventer
*
* If com.sun.jndi.LdapPoolManager class is loaded and the system property
* com.sun.jndi.ldap.connect.pool.timeout is set to a nonzero value, a daemon
* thread is started which can pin a webapp classloader if it is the first to
* load the LdapPoolManager.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*/
public class LDAPLeakPreventer extends AbstractLeakPreventer
{
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("com.sun.jndi.LdapPoolManager", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.trace("IGNORED", e);
}
}
}

View File

@ -1,40 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.preventers;
/**
* LoginConfigurationLeakPreventer
*
* The javax.security.auth.login.Configuration class keeps a static reference to the
* thread context classloader. We prevent a webapp context classloader being used for
* that by invoking the classloading here.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*/
public class LoginConfigurationLeakPreventer extends AbstractLeakPreventer
{
@Override
public void prevent(ClassLoader loader)
{
try
{
Class.forName("javax.security.auth.login.Configuration", true, loader);
}
catch (ClassNotFoundException e)
{
LOG.warn("Unable to load login config", e);
}
}
}

View File

@ -1,35 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.util.preventers;
import java.security.Security;
/**
* SecurityProviderLeakPreventer
*
* Some security providers, such as sun.security.pkcs11.SunPKCS11 start a deamon thread,
* which will use the thread context classloader. Load them here to ensure the classloader
* is not a webapp classloader.
*
* Inspired by Tomcat JreMemoryLeakPrevention
*/
public class SecurityProviderLeakPreventer extends AbstractLeakPreventer
{
@Override
public void prevent(ClassLoader loader)
{
Security.getProviders();
}
}

View File

@ -20,6 +20,8 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
@ -32,6 +34,7 @@ import org.eclipse.jetty.util.component.Dumpable;
* queue even if the task did not fire, which provides a huge benefit in the performance
* of garbage collection in young generation.
*/
@ManagedObject
public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler, Dumpable
{
private final String name;
@ -149,4 +152,22 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch
return scheduledFuture.cancel(false);
}
}
@ManagedAttribute("The name of the scheduler")
public String getName()
{
return name;
}
@ManagedAttribute("Whether the scheduler uses daemon threads")
public boolean isDaemon()
{
return daemon;
}
@ManagedAttribute("The number of scheduler threads")
public int getThreads()
{
return threads;
}
}