Author: markt
Date: Mon Apr 29 11:32:58 2013
New Revision: 1476972
URL: http://svn.apache.org/r1476972
Log:
Explicitly restrict HTTP upgraded connections to a max of one thread for read
and another for write.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1476972&r1=1476971&r2=1476972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Mon Apr 29
11:32:58 2013
@@ -2172,8 +2172,10 @@ public class AprEndpoint extends Abstrac
// Upgraded connections need to allow multiple threads to access
the
// connection at the same time to enable blocking IO to be used
when
// Servlet 3.1 NIO has been configured
- if (socket.isUpgraded()) {
- doRun();
+ if (socket.isUpgraded() && SocketStatus.OPEN_WRITE == status) {
+ synchronized (socket.getWriteThreadLock()) {
+ doRun();
+ }
} else {
synchronized (socket) {
doRun();
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1476972&r1=1476971&r2=1476972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Apr 29
11:32:58 2013
@@ -1533,8 +1533,11 @@ public class NioEndpoint extends Abstrac
// Upgraded connections need to allow multiple threads to access
the
// connection at the same time to enable blocking IO to be used
when
// NIO has been configured
- if (ka != null && ka.isUpgraded()) {
- doRun(key, ka);
+ if (ka != null && ka.isUpgraded() &&
+ SocketStatus.OPEN_WRITE == status) {
+ synchronized (ka.getWriteThreadLock()) {
+ doRun(key, ka);
+ }
} else {
synchronized (socket) {
doRun(key, ka);
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java?rev=1476972&r1=1476971&r2=1476972&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapper.java Mon Apr 29
11:32:58 2013
@@ -49,6 +49,16 @@ public class SocketWrapper<E> {
private final Lock blockingStatusReadLock;
private final WriteLock blockingStatusWriteLock;
+ /*
+ * In normal servlet processing only one thread is allowed to access the
+ * socket at a time. That is controlled by a lock on the socket for both
+ * read and writes). When HTTP upgrade is used, one read thread and one
+ * write thread are allowed to access the socket concurrently. In this case
+ * the lock on the socket is used for reads and the lock below is used for
+ * writes.
+ */
+ private final Object writeThreadLock = new Object();
+ public Object getWriteThreadLock() { return writeThreadLock; }
public SocketWrapper(E socket) {
this.socket = socket;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]