You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/03/04 20:26:38 UTC
[tomcat] branch 8.5.x updated: Fix
https://bz.apache.org/bugzilla/show_bug.cgi?id=63210
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push:
new 4ccde94 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63210
4ccde94 is described below
commit 4ccde94cd79791faeca6421512c51409770002b5
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 dd734ac..fe5ad1c 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 affd9dd..60de9c1 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 e620ee1..2a9fe56 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -89,6 +89,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 c1861ec..c424a6f 100644
--- a/webapps/docs/config/context.xml
+++ b/webapps/docs/config/context.xml
@@ -1203,7 +1203,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 c4f96bd..806964b 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org