From 4e0e889871ea7d65f406f75a0d529d67db328599 Mon Sep 17 00:00:00 2001 From: remm Date: Thu, 11 Oct 2007 00:29:00 +0000 Subject: [PATCH] - 43479: Memory leak cleaning up sendfile connections (submitted by the bug reporter). - 42925: No timeout for sendfile (fix TODO item that had been forgotten). git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@583650 13f79535-47bb-0310-9956-ffa450edef68 --- STATUS | 14 ++------------ java/org/apache/tomcat/util/net/AprEndpoint.java | 24 ++++++++++++++++++++++-- webapps/docs/changelog.xml | 6 ++++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/STATUS b/STATUS index e1c7a8b28..9ea00d8df 100644 --- a/STATUS +++ b/STATUS @@ -30,16 +30,6 @@ PATCHES PROPOSED TO BACKPORT: +1: remm, pero, funkman -1: -* 43479: Memory leak cleaning up sendfile connections (submitted by the bug reporter) - http://issues.apache.org/bugzilla/attachment.cgi?id=20883 - +1: remm, pero, funkman - -1: - -* 42925: No timeout for sendfile - http://issues.apache.org/bugzilla/attachment.cgi?id=20930 - +1: remm, pero, funkman - -1: - * Use newer eclipse jdt - old location is gone (reported by Jason Britian via email) update to jdt.loc=http://sunsite.informatik.rwth-aachen.de/eclipse/downloads/drops/R-3.3.1-200709211145/eclipse-JDT-3.3.1.zip +1: pero, funkman, remm @@ -47,9 +37,9 @@ PATCHES PROPOSED TO BACKPORT: * Call StopAwait at StandardServer.stop as port==-1 +1: pero - -1: + -1: remm (would like clarification on the sleep value, currently 100s) * Arrange doc of connectors. http://people.apache.org/~jfclere/patches/tc.docs.patch - +1: jfclere + +1: jfclere, remm -1: diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index 4e0161bb3..cebe15885 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -1695,7 +1695,7 @@ public class AprEndpoint { if (rv == Status.APR_SUCCESS) { sendfileCount--; } - sendfileData.remove(data); + sendfileData.remove(new Long(data.socket)); } /** @@ -1704,6 +1704,7 @@ public class AprEndpoint { */ public void run() { + long maintainTime = 0; // Loop until we receive a shutdown command while (running) { @@ -1717,6 +1718,8 @@ public class AprEndpoint { } while (sendfileCount < 1 && addS.size() < 1) { + // Reset maintain time. + maintainTime = 0; try { synchronized (this) { this.wait(); @@ -1745,6 +1748,8 @@ public class AprEndpoint { addS.clear(); } } + + maintainTime += pollTime; // Pool for the specified interval int rv = Poll.poll(sendfilePollset, pollTime, desc, false); if (rv > 0) { @@ -1810,7 +1815,22 @@ public class AprEndpoint { continue; } } - /* TODO: See if we need to call the maintain for sendfile poller */ + // Call maintain for the sendfile poller + if (soTimeout > 0 && maintainTime > 1000000L && running) { + rv = Poll.maintain(sendfilePollset, desc, true); + maintainTime = 0; + if (rv > 0) { + for (int n = 0; n < rv; n++) { + // Get the sendfile state + SendfileData state = sendfileData.get(new Long(desc[n])); + // Close socket and clear pool + remove(state); + // Destroy file descriptor pool, which should close the file + // Close the socket, as the response would be incomplete + Socket.destroy(state.socket); + } + } + } } catch (Throwable t) { log.error(sm.getString("endpoint.poll.error"), t); } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 6dd2c1283..cc3514395 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -121,6 +121,12 @@ Cookie parser refactoring, submitted by John Kew. (remm) + + 43479: Memory leak cleaning up sendfile connections, submitted by Chris Elving. (remm) + + + 42925: Add maintain for sendfile. (remm) + -- 2.11.0