[jbossweb-commits] JBossWeb SVN: r2280 - in branches/7.4.x/src/main/java/org/apache: coyote and 2 other directories.

jbossweb-commits at lists.jboss.org jbossweb-commits at lists.jboss.org
Wed Oct 16 06:48:33 EDT 2013


Author: remy.maucherat at jboss.com
Date: 2013-10-16 06:48:32 -0400 (Wed, 16 Oct 2013)
New Revision: 2280

Modified:
   branches/7.4.x/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
   branches/7.4.x/src/main/java/org/apache/coyote/Response.java
   branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java
   branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProtocol.java
   branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
   branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
   branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
Log:
- Some exception reporting.
- Be careful about using processChannel.

Modified: branches/7.4.x/src/main/java/org/apache/catalina/core/StandardWrapperValve.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/catalina/core/StandardWrapperValve.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/catalina/core/StandardWrapperValve.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -546,7 +546,12 @@
                     if (error) {
                         Throwable throwable = asyncContext.getError();
                         if (throwable == null) {
-                            throwable = new EOFException();
+                            throwable = response.getCoyoteResponse().getErrorException();
+                            if (throwable != null) {
+                                throwable = new IOException(throwable);
+                            } else {
+                                throwable = new EOFException();
+                            }
                         }
                         if (request.getReadListener() != null) { 
                             request.getReadListener().onError(throwable);

Modified: branches/7.4.x/src/main/java/org/apache/coyote/Response.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/Response.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/coyote/Response.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -110,7 +110,7 @@
     /**
      * Holds request error exception.
      */
-    protected Exception errorException = null;
+    protected Throwable errorException = null;
 
     /**
      * Has the charset been explicitly set.
@@ -262,8 +262,8 @@
      * Set the error Exception that occurred during
      * request processing.
      */
-    public void setErrorException(Exception ex) {
-    errorException = ex;
+    public void setErrorException(Throwable t) {
+        errorException = t;
     }
 
 
@@ -271,7 +271,7 @@
      * Get the Exception that occurred during request
      * processing.
      */
-    public Exception getErrorException() {
+    public Throwable getErrorException() {
         return errorException;
     }
 

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProcessor.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -301,7 +301,9 @@
 										// Reach the end of the stream
 										failed(null, attachment);
 									} else {
-										endpoint.processChannel(ch, null);
+										if (!endpoint.processChannel(attachment, null)) {
+										    closeChannel(attachment);
+										}
 									}
 								}
 

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProtocol.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProtocol.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/Http11NioProtocol.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -806,6 +806,7 @@
 		 * .AsynchronousSocketChannel, org.apache.tomcat.util.net.ChannelStatus)
 		 */
 		@Override
+		// FIXME: probably needs sync due to concurrent read/write possibilities
 		public synchronized SocketState event(NioChannel channel, SocketStatus status) {
 
 			Http11NioProcessor processor = connections.get(channel.getId());
@@ -848,7 +849,9 @@
 												if (nBytes < 0) {
 													failed(new ClosedChannelException(), endpoint);
 												} else {
-													endpoint.processChannel(ch, null);
+													if (!endpoint.processChannel(ch, null)) {
+													    endpoint.closeChannel(ch);
+													}
 												}
 											}
 
@@ -895,7 +898,7 @@
 				}
                 processor.startProcessing();
 
-				if (proto.secure && (proto.sslImplementation != null)) {
+                if (proto.secure && (proto.sslImplementation != null)) {
 					processor.setSSLSupport(((NioJSSEImplementation) proto.sslImplementation).getSSLSupport(channel));
 				} else {
 					processor.setSSLSupport(null);
@@ -913,9 +916,9 @@
 						// Call a read event right away
 					    state = event(channel, SocketStatus.OPEN_READ);
 					} else {
-						proto.endpoint.addEventChannel(channel, processor.getTimeout(),
+	                    proto.endpoint.addEventChannel(channel, processor.getTimeout(),
 								processor.getReadNotifications(), false,
-								processor.getResumeNotification(), false);
+	                            processor.getResumeNotification(), false);
 					}
 				} else {
 					recycledProcessors.offer(processor);

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioInputBuffer.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -123,17 +123,19 @@
 			        lastValid = pos + nBytes;
 			        latch.countDown();
 			        if (!processor.isProcessing() && processor.getReadNotifications()) {
-			            endpoint.processChannel(attachment, SocketStatus.OPEN_READ);
+			            if (!endpoint.processChannel(attachment, SocketStatus.OPEN_READ)) {
+			                endpoint.closeChannel(attachment);
+			            }
 			        }
 			    }
 			}
 
 			@Override
 			public void failed(Throwable exc, NioChannel attachment) {
-			    exc.printStackTrace();
+			    processor.getResponse().setErrorException(exc);
 			    endpoint.removeEventChannel(attachment);
-			    if (!processor.isProcessing()) {
-			        endpoint.processChannel(attachment, SocketStatus.ERROR);
+			    if (!endpoint.processChannel(attachment, SocketStatus.ERROR)) {
+			        endpoint.closeChannel(attachment);
 			    }
 			}
 		};
@@ -490,9 +492,10 @@
 		try {
 		    latch = new CountDownLatch(1);
 			ch.read(bb, ch, this.completionHandler);
-		} catch (Throwable t) {
+		} catch (Exception e) {
+		    processor.getResponse().setErrorException(e);
 			if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
-			    CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingRead(t);
+			    CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingRead(e);
 			}
 		}
 	}

Modified: branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/coyote/http11/InternalNioOutputBuffer.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -211,7 +211,9 @@
                         leftover.recycle();
                         latch.countDown();
                         if (!processor.isProcessing() && processor.getWriteNotification()) {
-                            endpoint.processChannel(attachment, SocketStatus.OPEN_WRITE);
+                            if (!endpoint.processChannel(attachment, SocketStatus.OPEN_WRITE)) {
+                                endpoint.closeChannel(attachment);
+                            }
                         }
                         return;
                     }
@@ -222,11 +224,11 @@
 
 			@Override
 			public void failed(Throwable exc, NioChannel attachment) {
-			    exc.printStackTrace();
+                processor.getResponse().setErrorException(exc);
 				endpoint.removeEventChannel(attachment);
-                if (!processor.isProcessing()) {
-                    endpoint.processChannel(attachment, SocketStatus.ERROR);
-                }
+				if (!endpoint.processChannel(attachment, SocketStatus.ERROR)) {
+				    endpoint.closeChannel(attachment);
+				}
 			}
 		};
 	}
@@ -308,6 +310,7 @@
 		    latch = new CountDownLatch(1);
 		    this.channel.write(this.bbuf, timeout, unit, this.channel, this.completionHandler);
 		} catch (Throwable t) {
+            processor.getResponse().setErrorException(t);
 			if (CoyoteLogger.HTTP_LOGGER.isDebugEnabled()) {
 			    CoyoteLogger.HTTP_LOGGER.errorWithNonBlockingWrite(t);
 			}
@@ -529,7 +532,12 @@
         }
 
         // Reset pointers
-        leftover.recycle();
+        byte[] leftoverBuf = leftover.getBuffer();
+        if (leftoverBuf != null && leftoverBuf.length > Constants.ASYNC_BUFFER_SIZE) {
+            leftover = new ByteChunk();
+        } else {
+            leftover.recycle();
+        }
         pos = 0;
         lastActiveFilter = -1;
         committed = false;
@@ -835,7 +843,6 @@
                     } catch (InterruptedException e) {
                         // Ignore
                     }
-                    // FIXME? throw new IOException(MESSAGES.invalidBacklog());
                 }
                 synchronized (completionHandler) {
                     leftover.append(chunk);

Modified: branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java
===================================================================
--- branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java	2013-10-15 17:30:15 UTC (rev 2279)
+++ branches/7.4.x/src/main/java/org/apache/tomcat/util/net/NioEndpoint.java	2013-10-16 10:48:32 UTC (rev 2280)
@@ -1271,7 +1271,9 @@
 					@Override
 					public void failed(Throwable exc, NioChannel attach) {
 						remove(attach);
-						processChannel(attach, SocketStatus.ERROR);
+						if (!processChannel(attach, SocketStatus.ERROR)) {
+						    closeChannel(attach);
+						}
 						// Recycle the completion handler
 						recycleHanlder(this);
 					}
@@ -1315,29 +1317,28 @@
 			} else {
 				info.flags = ChannelInfo.merge(info.flags, flag);
 			}
+
 			// Setting the channel timeout
 			info.timeout = date;
-
 			final NioChannel ch = channel;
-
 			if (info.resume()) {
 				remove(info);
 				if (!processChannel(ch, SocketStatus.OPEN_CALLBACK)) {
 					closeChannel(ch);
 				}
-			} else if (info.read()) {
-				try {
-					// Trying awaiting for read event
-					ch.awaitRead(ch, getCompletionHandler());
-				} catch (Exception e) {
-					// Ignore
-	                CoyoteLogger.UTIL_LOGGER.errorAwaitingRead(e);
-				}
 			} else if (info.write()) {
 				remove(info);
 				if (!processChannel(ch, SocketStatus.OPEN_WRITE)) {
 					closeChannel(ch);
 				}
+            } else if (info.read()) {
+                try {
+                    // Trying awaiting for read event
+                    ch.awaitRead(ch, getCompletionHandler());
+                } catch (Exception e) {
+                    // Ignore
+                    CoyoteLogger.UTIL_LOGGER.errorAwaitingRead(e);
+                }
 			} else if (info.wakeup()) {
 				remove(info);
 				// TODO



More information about the jbossweb-commits mailing list