[tomcat] 01/02: Improve Connector stop performance - primarily to speed up tests

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 3d60c5edc601bbb7f671d48bb4b7e77057dcaf48
Author: Mark Thomas 
AuthorDate: Mon Oct 11 13:51:05 2021 +0100

Improve Connector stop performance - primarily to speed up tests
---
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 17 +++
 java/org/apache/tomcat/util/net/Acceptor.java  | 35 ++
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  4 +--
 webapps/docs/changelog.xml |  8 +
 4 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 2938135..832119a 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1032,12 +1032,17 @@ public abstract class AbstractEndpoint {
 getLog().debug("Socket unlock completed for:" + 
unlockAddress);
 }
 }
-// Wait for upto 1000ms acceptor threads to unlock
-long waitLeft = 1000;
-while (waitLeft > 0 &&
-acceptor.getState() == AcceptorState.RUNNING) {
-Thread.sleep(5);
-waitLeft -= 5;
+// Wait for up to 1000ms acceptor threads to unlock. Particularly
+// for the unit tests, we want to exit this loop as quickly as
+// possible. However, we also don't want to trigger excessive CPU
+// usage if the unlock takes longer than expected. Therefore, we
+// initially wait for the unlock in a tight loop but if that takes
+// more than 1ms we start using short sleeps to reduce CPU usage.
+long startTime = System.nanoTime();
+while (startTime + 1_000_000_000 > System.nanoTime() && 
acceptor.getState() == AcceptorState.RUNNING) {
+if (startTime + 1_000_000 < System.nanoTime()) {
+Thread.sleep(1);
+}
 }
 } catch(Throwable t) {
 ExceptionUtils.handleThrowable(t);
diff --git a/java/org/apache/tomcat/util/net/Acceptor.java 
b/java/org/apache/tomcat/util/net/Acceptor.java
index c526145..b1083b2 100644
--- a/java/org/apache/tomcat/util/net/Acceptor.java
+++ b/java/org/apache/tomcat/util/net/Acceptor.java
@@ -68,18 +68,41 @@ public class Acceptor implements Runnable {
 public void run() {
 
 int errorDelay = 0;
+long pauseStart = 0;
 
 try {
 // Loop until we receive a shutdown command
 while (!stopCalled) {
 
-// Loop if endpoint is paused
+// Loop if endpoint is paused.
+// There are two likely scenarios here.
+// The first scenario is that Tomcat is shutting down. In this
+// case - and particularly for the unit tests - we want to exit
+// this loop as quickly as possible. The second scenario is a
+// genuine pause of the connector. In this case we want to 
avoid
+// excessive CPU usage.
+// Therefore, we start with a tight loop but if there isn't a
+// rapid transition to stop then sleeps are introduced.
+// < 1ms   - tight loop
+// 1ms to 10ms - 1ms sleep
+// > 10ms  - 10ms sleep
 while (endpoint.isPaused() && !stopCalled) {
-state = AcceptorState.PAUSED;
-try {
-Thread.sleep(50);
-} catch (InterruptedException e) {
-// Ignore
+if (state != AcceptorState.PAUSED) {
+pauseStart = System.nanoTime();
+// Entered pause state
+state = AcceptorState.PAUSED;
+}
+if ((System.nanoTime() - pauseStart) > 1_000_000) {
+// Paused for more than 1ms
+try {
+if ((System.nanoTime() - pauseStart) > 10_000_000) 
{
+Thread.sleep(10);
+} else {
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
 }
 }
 
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 2c56ddd..5fb0477 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
@@ -253,8 +253,8 @@ public class Nio2Endpoint extends 
AbstractJsseEndpoint 

[tomcat] 02/02: Implement new approahc to doHead(). Expand testing to cover HTTP/2.

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 8b5d5ee1fe8c47e3b80b591fedaddc81e5c51a24
Author: Mark Thomas 
AuthorDate: Mon Oct 11 14:39:44 2021 +0100

Implement new approahc to doHead(). Expand testing to cover HTTP/2.
---
 java/jakarta/servlet/http/HttpServlet.java |  19 +++-
 .../apache/catalina/connector/OutputBuffer.java|   8 +-
 java/org/apache/coyote/http2/Stream.java   |   5 +
 .../servlet/http/TestHttpServletDoHead.java| 113 -
 .../apache/coyote/http11/TestHttp11Processor.java  |  27 +++--
 test/org/apache/coyote/http2/Http2TestBase.java|  36 ++-
 .../org/apache/coyote/http2/TesterHttp2Parser.java |  34 +++
 webapps/docs/changelog.xml |  14 +++
 8 files changed, 214 insertions(+), 42 deletions(-)

diff --git a/java/jakarta/servlet/http/HttpServlet.java 
b/java/jakarta/servlet/http/HttpServlet.java
index ea9976c..f537321 100644
--- a/java/jakarta/servlet/http/HttpServlet.java
+++ b/java/jakarta/servlet/http/HttpServlet.java
@@ -31,6 +31,7 @@ import jakarta.servlet.AsyncEvent;
 import jakarta.servlet.AsyncListener;
 import jakarta.servlet.DispatcherType;
 import jakarta.servlet.GenericServlet;
+import jakarta.servlet.ServletConfig;
 import jakarta.servlet.ServletException;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.ServletRequest;
@@ -94,12 +95,21 @@ public abstract class HttpServlet extends GenericServlet {
 private static final String LSTRING_FILE = 
"jakarta.servlet.http.LocalStrings";
 private static final ResourceBundle lStrings = 
ResourceBundle.getBundle(LSTRING_FILE);
 
+/**
+ * @deprecated May be removed in a future release
+ *
+ * @since 6.0
+ */
+@Deprecated
+public static final String LEGACY_DO_HEAD = 
"jakarta.servlet.http.legacyDoHead";
+
 private final transient Object cachedAllowHeaderValueLock = new Object();
 /**
  * Cached value of the HTTP {@code Allow} header for this servlet.
  */
 private volatile String cachedAllowHeaderValue = null;
 
+private volatile boolean cachedUseLegacyDoHead;
 
 /**
  * Does nothing, because this is an abstract class.
@@ -109,6 +119,13 @@ public abstract class HttpServlet extends GenericServlet {
 }
 
 
+@Override
+public void init(ServletConfig config) throws ServletException {
+super.init(config);
+cachedUseLegacyDoHead = 
Boolean.parseBoolean(config.getInitParameter(LEGACY_DO_HEAD));
+}
+
+
 /**
  * Called by the server (via the service method) to
  * allow a servlet to handle a GET request.
@@ -241,7 +258,7 @@ public abstract class HttpServlet extends GenericServlet {
 protected void doHead(HttpServletRequest req, HttpServletResponse resp)
 throws ServletException, IOException {
 
-if (DispatcherType.INCLUDE.equals(req.getDispatcherType())) {
+if (DispatcherType.INCLUDE.equals(req.getDispatcherType()) || 
!cachedUseLegacyDoHead) {
 doGet(req, resp);
 } else {
 NoBodyResponse response = new NoBodyResponse(resp);
diff --git a/java/org/apache/catalina/connector/OutputBuffer.java 
b/java/org/apache/catalina/connector/OutputBuffer.java
index d7a6783..af2c9af 100644
--- a/java/org/apache/catalina/connector/OutputBuffer.java
+++ b/java/org/apache/catalina/connector/OutputBuffer.java
@@ -234,13 +234,9 @@ public class OutputBuffer extends Writer {
 flushCharBuffer();
 }
 
-if ((!coyoteResponse.isCommitted()) && 
(coyoteResponse.getContentLengthLong() == -1)
-&& !coyoteResponse.getRequest().method().equals("HEAD")) {
+if ((!coyoteResponse.isCommitted()) && 
(coyoteResponse.getContentLengthLong() == -1)) {
 // If this didn't cause a commit of the response, the final content
-// length can be calculated. Only do this if this is not a HEAD
-// request since in that case no body should have been written and
-// setting a value of zero here will result in an explicit content
-// length of zero being set on the response.
+// length can be calculated.
 if (!coyoteResponse.isCommitted()) {
 coyoteResponse.setContentLength(bb.remaining());
 }
diff --git a/java/org/apache/coyote/http2/Stream.java 
b/java/org/apache/coyote/http2/Stream.java
index cad1079..5ad9396 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -34,6 +34,7 @@ import org.apache.coyote.Request;
 import org.apache.coyote.Response;
 import org.apache.coyote.http11.HttpOutputBuffer;
 import org.apache.coyote.http11.OutputFilter;
+import org.apache.coyote.http11.filters.VoidOutputFilter;
 import org.apache.coyote.http2.HpackDecoder.HeaderEmitter;
 import org.apache.juli.logging.Log;
 i

[tomcat] branch main updated (d92a26c -> 8b5d5ee)

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


from d92a26c  Correct release date
 new 3d60c5e  Improve Connector stop performance - primarily to speed up 
tests
 new 8b5d5ee  Implement new approahc to doHead(). Expand testing to cover 
HTTP/2.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/jakarta/servlet/http/HttpServlet.java |  19 +++-
 .../apache/catalina/connector/OutputBuffer.java|   8 +-
 java/org/apache/coyote/http2/Stream.java   |   5 +
 .../apache/tomcat/util/net/AbstractEndpoint.java   |  17 ++--
 java/org/apache/tomcat/util/net/Acceptor.java  |  35 +--
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |   4 +-
 .../servlet/http/TestHttpServletDoHead.java| 113 -
 .../apache/coyote/http11/TestHttp11Processor.java  |  27 +++--
 test/org/apache/coyote/http2/Http2TestBase.java|  36 ++-
 .../org/apache/coyote/http2/TesterHttp2Parser.java |  21 ++--
 webapps/docs/changelog.xml |  22 
 11 files changed, 239 insertions(+), 68 deletions(-)
 copy java/org/apache/coyote/http2/StreamRunnable.java => 
test/org/apache/coyote/http2/TesterHttp2Parser.java (68%)

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 10.0.x updated: Improve Connector stop performance - primarily to speed up tests

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
 new 21ec01f  Improve Connector stop performance - primarily to speed up 
tests
21ec01f is described below

commit 21ec01ff8f28c09bf821ec0d40c449a923803022
Author: Mark Thomas 
AuthorDate: Mon Oct 11 13:51:05 2021 +0100

Improve Connector stop performance - primarily to speed up tests
---
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 17 +++
 java/org/apache/tomcat/util/net/Acceptor.java  | 35 ++
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  4 +--
 webapps/docs/changelog.xml |  8 +
 4 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 437e1da..cde1dd6 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1042,12 +1042,17 @@ public abstract class AbstractEndpoint {
 getLog().debug("Socket unlock completed for:" + 
unlockAddress);
 }
 }
-// Wait for upto 1000ms acceptor threads to unlock
-long waitLeft = 1000;
-while (waitLeft > 0 &&
-acceptor.getState() == AcceptorState.RUNNING) {
-Thread.sleep(5);
-waitLeft -= 5;
+// Wait for up to 1000ms acceptor threads to unlock. Particularly
+// for the unit tests, we want to exit this loop as quickly as
+// possible. However, we also don't want to trigger excessive CPU
+// usage if the unlock takes longer than expected. Therefore, we
+// initially wait for the unlock in a tight loop but if that takes
+// more than 1ms we start using short sleeps to reduce CPU usage.
+long startTime = System.nanoTime();
+while (startTime + 1_000_000_000 > System.nanoTime() && 
acceptor.getState() == AcceptorState.RUNNING) {
+if (startTime + 1_000_000 < System.nanoTime()) {
+Thread.sleep(1);
+}
 }
 } catch(Throwable t) {
 ExceptionUtils.handleThrowable(t);
diff --git a/java/org/apache/tomcat/util/net/Acceptor.java 
b/java/org/apache/tomcat/util/net/Acceptor.java
index ff810e9..3fa4f96 100644
--- a/java/org/apache/tomcat/util/net/Acceptor.java
+++ b/java/org/apache/tomcat/util/net/Acceptor.java
@@ -69,18 +69,41 @@ public class Acceptor implements Runnable {
 public void run() {
 
 int errorDelay = 0;
+long pauseStart = 0;
 
 try {
 // Loop until we receive a shutdown command
 while (!stopCalled) {
 
-// Loop if endpoint is paused
+// Loop if endpoint is paused.
+// There are two likely scenarios here.
+// The first scenario is that Tomcat is shutting down. In this
+// case - and particularly for the unit tests - we want to exit
+// this loop as quickly as possible. The second scenario is a
+// genuine pause of the connector. In this case we want to 
avoid
+// excessive CPU usage.
+// Therefore, we start with a tight loop but if there isn't a
+// rapid transition to stop then sleeps are introduced.
+// < 1ms   - tight loop
+// 1ms to 10ms - 1ms sleep
+// > 10ms  - 10ms sleep
 while (endpoint.isPaused() && !stopCalled) {
-state = AcceptorState.PAUSED;
-try {
-Thread.sleep(50);
-} catch (InterruptedException e) {
-// Ignore
+if (state != AcceptorState.PAUSED) {
+pauseStart = System.nanoTime();
+// Entered pause state
+state = AcceptorState.PAUSED;
+}
+if ((System.nanoTime() - pauseStart) > 1_000_000) {
+// Paused for more than 1ms
+try {
+if ((System.nanoTime() - pauseStart) > 10_000_000) 
{
+Thread.sleep(10);
+} else {
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
 }
 }
 
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 3ac5324..be724c4 100644
---

[tomcat] branch 9.0.x updated: Improve Connector stop performance - primarily to speed up tests

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new 82b1348  Improve Connector stop performance - primarily to speed up 
tests
82b1348 is described below

commit 82b1348c8bc65997c70cf93d0b76a6f165aa1272
Author: Mark Thomas 
AuthorDate: Mon Oct 11 13:51:05 2021 +0100

Improve Connector stop performance - primarily to speed up tests
---
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 17 +++
 java/org/apache/tomcat/util/net/Acceptor.java  | 35 ++
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  |  4 +--
 webapps/docs/changelog.xml |  8 +
 4 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 6d4614f..d5d0e25 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1071,12 +1071,17 @@ public abstract class AbstractEndpoint {
 getLog().debug("Socket unlock completed for:" + 
unlockAddress);
 }
 }
-// Wait for upto 1000ms acceptor threads to unlock
-long waitLeft = 1000;
-while (waitLeft > 0 &&
-acceptor.getState() == AcceptorState.RUNNING) {
-Thread.sleep(5);
-waitLeft -= 5;
+// Wait for up to 1000ms acceptor threads to unlock. Particularly
+// for the unit tests, we want to exit this loop as quickly as
+// possible. However, we also don't want to trigger excessive CPU
+// usage if the unlock takes longer than expected. Therefore, we
+// initially wait for the unlock in a tight loop but if that takes
+// more than 1ms we start using short sleeps to reduce CPU usage.
+long startTime = System.nanoTime();
+while (startTime + 1_000_000_000 > System.nanoTime() && 
acceptor.getState() == AcceptorState.RUNNING) {
+if (startTime + 1_000_000 < System.nanoTime()) {
+Thread.sleep(1);
+}
 }
 } catch(Throwable t) {
 ExceptionUtils.handleThrowable(t);
diff --git a/java/org/apache/tomcat/util/net/Acceptor.java 
b/java/org/apache/tomcat/util/net/Acceptor.java
index ff810e9..3fa4f96 100644
--- a/java/org/apache/tomcat/util/net/Acceptor.java
+++ b/java/org/apache/tomcat/util/net/Acceptor.java
@@ -69,18 +69,41 @@ public class Acceptor implements Runnable {
 public void run() {
 
 int errorDelay = 0;
+long pauseStart = 0;
 
 try {
 // Loop until we receive a shutdown command
 while (!stopCalled) {
 
-// Loop if endpoint is paused
+// Loop if endpoint is paused.
+// There are two likely scenarios here.
+// The first scenario is that Tomcat is shutting down. In this
+// case - and particularly for the unit tests - we want to exit
+// this loop as quickly as possible. The second scenario is a
+// genuine pause of the connector. In this case we want to 
avoid
+// excessive CPU usage.
+// Therefore, we start with a tight loop but if there isn't a
+// rapid transition to stop then sleeps are introduced.
+// < 1ms   - tight loop
+// 1ms to 10ms - 1ms sleep
+// > 10ms  - 10ms sleep
 while (endpoint.isPaused() && !stopCalled) {
-state = AcceptorState.PAUSED;
-try {
-Thread.sleep(50);
-} catch (InterruptedException e) {
-// Ignore
+if (state != AcceptorState.PAUSED) {
+pauseStart = System.nanoTime();
+// Entered pause state
+state = AcceptorState.PAUSED;
+}
+if ((System.nanoTime() - pauseStart) > 1_000_000) {
+// Paused for more than 1ms
+try {
+if ((System.nanoTime() - pauseStart) > 10_000_000) 
{
+Thread.sleep(10);
+} else {
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
 }
 }
 
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 88f0382..365fe3a 100644
--- a

buildbot failure in on tomcat-10.0.x

2021-10-11 Thread buildbot
The Buildbot has detected a new failure on builder tomcat-10.0.x while building 
tomcat. Full details are available at:
https://ci.apache.org/builders/tomcat-10.0.x/builds/183

Buildbot URL: https://ci.apache.org/

Buildslave for this Build: asf946_ubuntu

Build Reason: The AnyBranchScheduler scheduler named 'on-tomcat-10.0-commit' 
triggered this build
Build Source Stamp: [branch 10.0.x] 21ec01ff8f28c09bf821ec0d40c449a923803022
Blamelist: Mark Thomas 

BUILD FAILED: failed compile_1

Sincerely,
 -The Buildbot




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 8.5.x updated: Improve Connector stop performance - primarily to speed up tests

2021-10-11 Thread markt
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 3b82538  Improve Connector stop performance - primarily to speed up 
tests
3b82538 is described below

commit 3b82538e9d1e5da932ba4dff13c3201ac7c39e27
Author: Mark Thomas 
AuthorDate: Mon Oct 11 16:48:26 2021 +0100

Improve Connector stop performance - primarily to speed up tests
---
 .../apache/tomcat/util/net/AbstractEndpoint.java   | 14 
 java/org/apache/tomcat/util/net/AprEndpoint.java   | 35 +++
 java/org/apache/tomcat/util/net/Nio2Endpoint.java  | 39 +-
 java/org/apache/tomcat/util/net/NioEndpoint.java   | 39 +-
 webapps/docs/changelog.xml |  8 +
 5 files changed, 113 insertions(+), 22 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AbstractEndpoint.java 
b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
index 9aad8c2..8830658 100644
--- a/java/org/apache/tomcat/util/net/AbstractEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AbstractEndpoint.java
@@ -1022,6 +1022,20 @@ public abstract class AbstractEndpoint {
 waitLeft -= 5;
 }
 }
+// Wait for up to 1000ms acceptor threads to unlock. Particularly
+// for the unit tests, we want to exit this loop as quickly as
+// possible. However, we also don't want to trigger excessive CPU
+// usage if the unlock takes longer than expected. Therefore, we
+// initially wait for the unlock in a tight loop but if that takes
+// more than 1ms we start using short sleeps to reduce CPU usage.
+long startTime = System.nanoTime();
+for (Acceptor acceptor : acceptors) {
+while (startTime + 1_000_000_000 > System.nanoTime() && 
acceptor.getState() == AcceptorState.RUNNING) {
+if (startTime + 1_000_000 < System.nanoTime()) {
+Thread.sleep(1);
+}
+}
+}
 } catch(Throwable t) {
 ExceptionUtils.handleThrowable(t);
 if (getLog().isDebugEnabled()) {
diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 413a8ad..eda0abf 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -803,17 +803,40 @@ public class AprEndpoint extends AbstractEndpoint 
implements SNICallBack {
 public void run() {
 
 int errorDelay = 0;
+long pauseStart = 0;
 
 // Loop until we receive a shutdown command
 while (running) {
 
-// Loop if endpoint is paused
+// Loop if endpoint is paused.
+// There are two likely scenarios here.
+// The first scenario is that Tomcat is shutting down. In this
+// case - and particularly for the unit tests - we want to exit
+// this loop as quickly as possible. The second scenario is a
+// genuine pause of the connector. In this case we want to 
avoid
+// excessive CPU usage.
+// Therefore, we start with a tight loop but if there isn't a
+// rapid transition to stop then sleeps are introduced.
+// < 1ms   - tight loop
+// 1ms to 10ms - 1ms sleep
+// > 10ms  - 10ms sleep
 while (paused && running) {
-state = AcceptorState.PAUSED;
-try {
-Thread.sleep(50);
-} catch (InterruptedException e) {
-// Ignore
+if (state != AcceptorState.PAUSED) {
+pauseStart = System.nanoTime();
+// Entered pause state
+state = AcceptorState.PAUSED;
+}
+if ((System.nanoTime() - pauseStart) > 1_000_000) {
+// Paused for more than 1ms
+try {
+if ((System.nanoTime() - pauseStart) > 10_000_000) 
{
+Thread.sleep(10);
+} else {
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
 }
 }
 
diff --git a/java/org/apache/tomcat/util/net/Nio2Endpoint.java 
b/java/org/apache/tomcat/util/net/Nio2Endpoint.java
index 5e0dfe1..a2e0bd3 100644
--- a/java/org/apache/tomcat/util/net/Nio2Endpoint.java
+++ b/java/org/apache/

[tomcat] branch main updated: Better debug logging

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
 new 96533b8  Better debug logging
96533b8 is described below

commit 96533b8b8efae2c13b020c7d5b31cb2d606df10c
Author: Mark Thomas 
AuthorDate: Mon Oct 11 17:01:20 2021 +0100

Better debug logging
---
 test/jakarta/servlet/http/TestHttpServletDoHead.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/test/jakarta/servlet/http/TestHttpServletDoHead.java 
b/test/jakarta/servlet/http/TestHttpServletDoHead.java
index e7a5426..400e791 100644
--- a/test/jakarta/servlet/http/TestHttpServletDoHead.java
+++ b/test/jakarta/servlet/http/TestHttpServletDoHead.java
@@ -167,8 +167,8 @@ public class TestHttpServletDoHead extends Http2TestBase {
 int i = 0;
 for (; i < getHeaders.length; i++) {
 // Headers should be the same, ignoring the first character which 
is the steam ID
-Assert.assertEquals(getHeaders[i].charAt(0), '3');
-Assert.assertEquals(headHeaders[i].charAt(0), '5');
+Assert.assertEquals(getHeaders[i], '3', getHeaders[i].charAt(0));
+Assert.assertEquals(headHeaders[i], '5', headHeaders[i].charAt(0));
 Assert.assertEquals(getHeaders[i].substring(1), 
headHeaders[i].substring(1));
 }
 

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: buildbot failure in on tomcat-10.0.x

2021-10-11 Thread Mark Thomas

On 11/10/2021 16:44, build...@apache.org wrote:

The Buildbot has detected a new failure on builder tomcat-10.0.x while building 
tomcat. Full details are available at:
 https://ci.apache.org/builders/tomcat-10.0.x/builds/183

Buildbot URL: https://ci.apache.org/

Buildslave for this Build: asf946_ubuntu

Build Reason: The AnyBranchScheduler scheduler named 'on-tomcat-10.0-commit' 
triggered this build
Build Source Stamp: [branch 10.0.x] 21ec01ff8f28c09bf821ec0d40c449a923803022
Blamelist: Mark Thomas 

BUILD FAILED: failed compile_1


The connector shutdown improvements are triggering a number of failures 
with APR. Initial analysis suggests the connector is shutting down 
before an in-progress write completes.


I'm investigating in more detail now.

On the plus side, this looks to have made a long standard APR issue 
(occasional crashes on stop) much more repeatable.


Mark

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



buildbot failure in on tomcat-9.0.x

2021-10-11 Thread buildbot
The Buildbot has detected a new failure on builder tomcat-9.0.x while building 
tomcat. Full details are available at:
https://ci.apache.org/builders/tomcat-9.0.x/builds/154

Buildbot URL: https://ci.apache.org/

Buildslave for this Build: asf946_ubuntu

Build Reason: The AnyBranchScheduler scheduler named 'on-tomcat-9.0-commit' 
triggered this build
Build Source Stamp: [branch 9.0.x] 82b1348c8bc65997c70cf93d0b76a6f165aa1272
Blamelist: Mark Thomas 

BUILD FAILED: failed compile_1

Sincerely,
 -The Buildbot




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 10.0.x updated: Refactor the APR/native connector shutdown

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 10.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.0.x by this push:
 new 4d3ee01  Refactor the APR/native connector shutdown
4d3ee01 is described below

commit 4d3ee01d14a330029f9fb75702f4658e744a8ae1
Author: Mark Thomas 
AuthorDate: Mon Oct 11 21:07:48 2021 +0100

Refactor the APR/native connector shutdown

Hopefully reduce the possibility of a JVM crash during the connector
shutdown.
---
 java/org/apache/tomcat/util/net/AprEndpoint.java | 46 +++-
 webapps/docs/changelog.xml   |  4 +++
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index f2e3973..4f44e62 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -551,11 +551,13 @@ public class AprEndpoint extends 
AbstractEndpoint implements SNICallB
 }
 if (running) {
 running = false;
+// Stop new connections being accepted.
 acceptor.stop(10);
+
+// Stop the Poller calling select
 poller.stop();
-for (SocketWrapperBase socketWrapper : connections.values()) 
{
-socketWrapper.close();
-}
+
+// Wait for the acceptor to shutdown
 if (acceptor.getState() != AcceptorState.ENDED && 
!getBindOnInit()) {
 log.warn(sm.getString("endpoint.warn.unlockAcceptorFailed", 
acceptor.getThreadName()));
 // If the Acceptor is still running force
@@ -565,12 +567,40 @@ public class AprEndpoint extends 
AbstractEndpoint implements SNICallB
 serverSock = 0;
 }
 }
-// Close any sockets not in the poller performing blocking
-// read/writes. Need to do this before destroying the poller since
-// that will also destroy the root pool for these sockets.
-for (Long s : connections.keySet()) {
-Socket.shutdown(s.longValue(), Socket.APR_SHUTDOWN_READWRITE);
+
+// Wait for Poller to stop
+int waitMillis = 0;
+try {
+while (poller.pollerThread.isAlive() && waitMillis < 1) {
+waitMillis++;
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
+
+// Close the SocketWrapper for each open connection - this should
+// trigger a IOException when the app (or container) tries to 
write.
+// Use the blocking status write lock as a proxy for a lock on
+// writing to the socket. Don't want to close it while another
+// thread is writing as that could trigger a JVM crash.
+for (SocketWrapperBase socketWrapper : connections.values()) 
{
+WriteLock wl = ((AprSocketWrapper) 
socketWrapper).getBlockingStatusWriteLock();
+wl.lock();
+try {
+socketWrapper.close();
+} finally {
+wl.unlock();
+}
+}
+
+for (Long socket : connections.keySet()) {
+// Close the APR Socket. Need to do this before destroying the
+// poller since that will also destroy the root pool for these
+// sockets.
+Socket.shutdown(socket.longValue(), 
Socket.APR_SHUTDOWN_READWRITE);
 }
+
 try {
 poller.destroy();
 } catch (Exception e) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4fadb0b..2b5e136 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,10 @@
 Improve performance of Connector shutdown - primarily to reduce the 
time
 it takes to run the test suite. (markt)
   
+  
+Refactor the APR/native connector shutdown to reduce the possibility of
+a JVM crash during the connector shutdown. (markt)
+  
 
   
   

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[tomcat] branch 9.0.x updated: Refactor the APR/native connector shutdown

2021-10-11 Thread markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
 new e1b2000  Refactor the APR/native connector shutdown
e1b2000 is described below

commit e1b200084010ae3a40c3716ad2af1c65095f6528
Author: Mark Thomas 
AuthorDate: Mon Oct 11 21:07:48 2021 +0100

Refactor the APR/native connector shutdown

Hopefully reduce the possibility of a JVM crash during the connector
shutdown.
---
 java/org/apache/tomcat/util/net/AprEndpoint.java | 46 +++-
 webapps/docs/changelog.xml   |  4 +++
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java 
b/java/org/apache/tomcat/util/net/AprEndpoint.java
index 9cdf9de..725195a 100644
--- a/java/org/apache/tomcat/util/net/AprEndpoint.java
+++ b/java/org/apache/tomcat/util/net/AprEndpoint.java
@@ -547,11 +547,13 @@ public class AprEndpoint extends 
AbstractEndpoint implements SNICallB
 }
 if (running) {
 running = false;
+// Stop new connections being accepted.
 acceptor.stop(10);
+
+// Stop the Poller calling select
 poller.stop();
-for (SocketWrapperBase socketWrapper : connections.values()) 
{
-socketWrapper.close();
-}
+
+// Wait for the acceptor to shutdown
 if (acceptor.getState() != AcceptorState.ENDED && 
!getBindOnInit()) {
 log.warn(sm.getString("endpoint.warn.unlockAcceptorFailed", 
acceptor.getThreadName()));
 // If the Acceptor is still running force
@@ -561,12 +563,40 @@ public class AprEndpoint extends 
AbstractEndpoint implements SNICallB
 serverSock = 0;
 }
 }
-// Close any sockets not in the poller performing blocking
-// read/writes. Need to do this before destroying the poller since
-// that will also destroy the root pool for these sockets.
-for (Long s : connections.keySet()) {
-Socket.shutdown(s.longValue(), Socket.APR_SHUTDOWN_READWRITE);
+
+// Wait for Poller to stop
+int waitMillis = 0;
+try {
+while (poller.pollerThread.isAlive() && waitMillis < 1) {
+waitMillis++;
+Thread.sleep(1);
+}
+} catch (InterruptedException e) {
+// Ignore
+}
+
+// Close the SocketWrapper for each open connection - this should
+// trigger a IOException when the app (or container) tries to 
write.
+// Use the blocking status write lock as a proxy for a lock on
+// writing to the socket. Don't want to close it while another
+// thread is writing as that could trigger a JVM crash.
+for (SocketWrapperBase socketWrapper : connections.values()) 
{
+WriteLock wl = ((AprSocketWrapper) 
socketWrapper).getBlockingStatusWriteLock();
+wl.lock();
+try {
+socketWrapper.close();
+} finally {
+wl.unlock();
+}
+}
+
+for (Long socket : connections.keySet()) {
+// Close the APR Socket. Need to do this before destroying the
+// poller since that will also destroy the root pool for these
+// sockets.
+Socket.shutdown(socket.longValue(), 
Socket.APR_SHUTDOWN_READWRITE);
 }
+
 try {
 poller.destroy();
 } catch (Exception e) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 97949d4a1..5c67c54 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,10 @@
 Improve performance of Connector shutdown - primarily to reduce the 
time
 it takes to run the test suite. (markt)
   
+  
+Refactor the APR/native connector shutdown to reduce the possibility of
+a JVM crash during the connector shutdown. (markt)
+  
 
   
   

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



buildbot success in on tomcat-10.0.x

2021-10-11 Thread buildbot
The Buildbot has detected a restored build on builder tomcat-10.0.x while 
building tomcat. Full details are available at:
https://ci.apache.org/builders/tomcat-10.0.x/builds/184

Buildbot URL: https://ci.apache.org/

Buildslave for this Build: asf946_ubuntu

Build Reason: The AnyBranchScheduler scheduler named 'on-tomcat-10.0-commit' 
triggered this build
Build Source Stamp: [branch 10.0.x] 4d3ee01d14a330029f9fb75702f4658e744a8ae1
Blamelist: Mark Thomas 

Build succeeded!

Sincerely,
 -The Buildbot




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



buildbot success in on tomcat-9.0.x

2021-10-11 Thread buildbot
The Buildbot has detected a restored build on builder tomcat-9.0.x while 
building tomcat. Full details are available at:
https://ci.apache.org/builders/tomcat-9.0.x/builds/155

Buildbot URL: https://ci.apache.org/

Buildslave for this Build: asf946_ubuntu

Build Reason: The AnyBranchScheduler scheduler named 'on-tomcat-9.0-commit' 
triggered this build
Build Source Stamp: [branch 9.0.x] e1b200084010ae3a40c3716ad2af1c65095f6528
Blamelist: Mark Thomas 

Build succeeded!

Sincerely,
 -The Buildbot




-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: [tomcat] 02/02: Implement new approahc to doHead(). Expand testing to cover HTTP/2.

2021-10-11 Thread Christopher Schultz

Mark,

On 10/11/21 10:04, ma...@apache.org wrote:

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 8b5d5ee1fe8c47e3b80b591fedaddc81e5c51a24
Author: Mark Thomas 
AuthorDate: Mon Oct 11 14:39:44 2021 +0100

 Implement new approahc to doHead(). Expand testing to cover HTTP/2.
---
  java/jakarta/servlet/http/HttpServlet.java |  19 +++-
  .../apache/catalina/connector/OutputBuffer.java|   8 +-
  java/org/apache/coyote/http2/Stream.java   |   5 +
  .../servlet/http/TestHttpServletDoHead.java| 113 -
  .../apache/coyote/http11/TestHttp11Processor.java  |  27 +++--
  test/org/apache/coyote/http2/Http2TestBase.java|  36 ++-
  .../org/apache/coyote/http2/TesterHttp2Parser.java |  34 +++
  webapps/docs/changelog.xml |  14 +++
  8 files changed, 214 insertions(+), 42 deletions(-)

diff --git a/java/jakarta/servlet/http/HttpServlet.java 
b/java/jakarta/servlet/http/HttpServlet.java
index ea9976c..f537321 100644
--- a/java/jakarta/servlet/http/HttpServlet.java
+++ b/java/jakarta/servlet/http/HttpServlet.java
@@ -31,6 +31,7 @@ import jakarta.servlet.AsyncEvent;
  import jakarta.servlet.AsyncListener;
  import jakarta.servlet.DispatcherType;
  import jakarta.servlet.GenericServlet;
+import jakarta.servlet.ServletConfig;
  import jakarta.servlet.ServletException;
  import jakarta.servlet.ServletOutputStream;
  import jakarta.servlet.ServletRequest;
@@ -94,12 +95,21 @@ public abstract class HttpServlet extends GenericServlet {
  private static final String LSTRING_FILE = 
"jakarta.servlet.http.LocalStrings";
  private static final ResourceBundle lStrings = 
ResourceBundle.getBundle(LSTRING_FILE);
  
+/**

+ * @deprecated May be removed in a future release
+ *
+ * @since 6.0
+ */
+@Deprecated
+public static final String LEGACY_DO_HEAD = 
"jakarta.servlet.http.legacyDoHead";


Since 6.0? Looks like you are adding it to 10.x.

Also, is it appropriate to use the "jakarta.*" namespace, here?


+  
+Refactor HttpServlet so the default doHead()
+implementation now calls doGet() and relies on the
+container to ensure that the response body is not sent. The previous
+behaviour (wrapping the response) may be enabled per Servlet by setting
+the jakarta.servlet.http.legacyDoHead Servlet
+initialisation parameter to true. This aligns Tomcat with
+recent changes updates for Servlet 6.0 in the Jakarta Servlet
+specification project. (markt)
+  


Hmm, okay. Should we say "@since Servlet 6.0" since it's not clear what 
the version means? Or, because it's in HttpServlet (which is defined by 
servlet.spec), is it implied that all versions will mean "(of the 
servlet spec)"?


-chris

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



[GitHub] [tomcat] hdeadman opened a new pull request #454: Differentiate log messages in KubernetesMembershipProvider with a param

2021-10-11 Thread GitBox


hdeadman opened a new pull request #454:
URL: https://github.com/apache/tomcat/pull/454


   The same log message is used for 6 different warning messages so this adds a 
parameter that can be used to tie the log message to the particular warning. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org