This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 39b11dc Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63210 39b11dc is described below commit 39b11dc314db8b78c0a9ac67eda5cb0179462eb2 Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Mar 4 20:23:09 2019 +0000 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63210 Ensure that the Apache Commons DBCP 2 based default connection pool is correctly shutdown when it is no longer required. This ensures that a non-daemon thread is not left running that will prevent Tomcat from shutting down cleanly. --- java/org/apache/catalina/core/NamingContextListener.java | 8 ++++++++ java/org/apache/tomcat/util/descriptor/web/ContextResource.java | 6 ++++++ webapps/docs/changelog.xml | 6 ++++++ webapps/docs/config/context.xml | 6 +++++- webapps/docs/config/globalresources.xml | 6 +++++- 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/core/NamingContextListener.java b/java/org/apache/catalina/core/NamingContextListener.java index 7bd69cd..5c124c8 100644 --- a/java/org/apache/catalina/core/NamingContextListener.java +++ b/java/org/apache/catalina/core/NamingContextListener.java @@ -60,6 +60,7 @@ import org.apache.naming.ResourceLinkRef; import org.apache.naming.ResourceRef; import org.apache.naming.ServiceRef; import org.apache.naming.TransactionRef; +import org.apache.naming.factory.Constants; import org.apache.naming.factory.ResourceLinkFactory; import org.apache.tomcat.util.descriptor.web.ContextEjb; import org.apache.tomcat.util.descriptor.web.ContextEnvironment; @@ -1010,6 +1011,13 @@ public class NamingContextListener if (("javax.sql.DataSource".equals(ref.getClassName()) || "javax.sql.XADataSource".equals(ref.getClassName())) && resource.getSingleton()) { + String factory = (String) resource.getProperty("factory"); + if ((factory == null || factory.equals(Constants.DBCP_DATASOURCE_FACTORY)) && + !resource.getCloseMethodConfigured()) { + // Using Tomcat's built-in factory (DBCP2) and DBCP2 DataSources + // require an explicit close + resource.setCloseMethod("close"); + } try { ObjectName on = createObjectName(resource); Object actualResource = envCtx.lookup(resource.getName()); diff --git a/java/org/apache/tomcat/util/descriptor/web/ContextResource.java b/java/org/apache/tomcat/util/descriptor/web/ContextResource.java index f31905a..dd3de30 100644 --- a/java/org/apache/tomcat/util/descriptor/web/ContextResource.java +++ b/java/org/apache/tomcat/util/descriptor/web/ContextResource.java @@ -85,15 +85,21 @@ public class ContextResource extends ResourceBase { * collection. */ private String closeMethod = null; + private boolean closeMethodConfigured = false; public String getCloseMethod() { return closeMethod; } public void setCloseMethod(String closeMethod) { + closeMethodConfigured = true; this.closeMethod = closeMethod; } + public boolean getCloseMethodConfigured() { + return closeMethodConfigured; + } + // --------------------------------------------------------- Public Methods diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6833050..279096a 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -63,6 +63,12 @@ <code>maxLogMessageBufferSize</code> that were accidentally removed. (markt) </fix> + <fix> + <bug>63210</bug>: Ensure that the Apache Commons DBCP 2 based default + connection pool is correctly shutdown when it is no longer required. + This ensures that a non-daemon thread is not left running that will + prevent Tomcat from shutting down cleanly. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index b84d79e..27a49a4 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -1215,7 +1215,11 @@ false. If not specified, no default is defined and no close method will be called.</p> <p>For Apache Commons DBCP 2 and Apache Tomcat JDBC connection pools - you can use <code>closeMethod="close"</code>.</p> + you can use <code>closeMethod="close"</code>. Note that Apache Commons + DBCP 2 requires this to be set for a clean shutdown. When using the + default Tomcat connection pool (based on DBCP 2) Tomcat will set this + attribute automatically unless it is explictly set to the empty + string.</p> </attribute> <attribute name="description" required="false"> diff --git a/webapps/docs/config/globalresources.xml b/webapps/docs/config/globalresources.xml index 8f20b64..e9e26ef 100644 --- a/webapps/docs/config/globalresources.xml +++ b/webapps/docs/config/globalresources.xml @@ -188,7 +188,11 @@ false. If not specified, no default is defined and no close method will be called.</p> <p>For Apache Commons DBCP 2 and Apache Tomcat JDBC connection pools - you can use <code>closeMethod="close"</code>.</p> + you can use <code>closeMethod="close"</code>. Note that Apache Commons + DBCP 2 requires this to be set for a clean shutdown. When using the + default Tomcat connection pool (based on DBCP 2) Tomcat will set this + attribute automatically unless it is explictly set to the empty + string.</p> </attribute> <attribute name="description" required="false"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org