Author: mturk
Date: Thu Aug 31 00:29:25 2006
New Revision: 438828

URL: http://svn.apache.org/viewvc?rev=438828&view=rev
Log:
Tomcat can fail in the middle of the post request.
Do not handle this as client error. Introduce
JK_SERVER_ERROR so we can separate client and backend
error states. This also means that if the Tomcat fails
in the middle of request without recovery we will
return 500 instead 400 error.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_ajp13.h
    tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
    tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c

Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp13.h
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp13.h?rev=438828&r1=438827&r2=438828&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp13.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp13.h Thu Aug 31 00:29:25 2006
@@ -40,6 +40,7 @@
 #define JK_INTERNAL_ERROR           (-2)
 #define JK_FATAL_ERROR              (-3)
 #define JK_CLIENT_ERROR             (-4)
+#define JK_SERVER_ERROR             (-5)
 #define AJP13_MAX_SEND_BODY_SZ      (DEF_BUFFER_SZ - 6)
 #define AJP13_DEF_TIMEOUT           (0) /* Idle timout for pooled connections 
*/
 

Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c?rev=438828&r1=438827&r2=438828&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c Thu Aug 31 
00:29:25 2006
@@ -1264,7 +1264,7 @@
             jk_log(l, JK_LOG_ERROR, "Error resending request body (%d)",
                    postlen);
             JK_TRACE_EXIT(l);
-            return JK_FALSE;
+            return JK_SERVER_ERROR;
         }
         else {
             if (JK_IS_DEBUG_LEVEL(l))
@@ -1285,7 +1285,7 @@
                        "Error resending request body (lb mode) (%d)",
                        postlen);
                 JK_TRACE_EXIT(l);
-                return JK_FALSE;
+                return JK_SERVER_ERROR;
             }
         }
         else {
@@ -1317,7 +1317,7 @@
                 /* the browser stop sending data, no need to recover */
                 op->recoverable = JK_FALSE;
                 JK_TRACE_EXIT(l);
-                return len;
+                return JK_CLIENT_ERROR;
             }
 
             /* If a RECOVERY buffer is available in LB mode, fill it */
@@ -1333,7 +1333,7 @@
                 ae->sd = -1;
                 jk_log(l, JK_LOG_ERROR, "Error sending request body");
                 JK_TRACE_EXIT(l);
-                return JK_FALSE;
+                return JK_SERVER_ERROR;
             }
         }
     }
@@ -1393,7 +1393,7 @@
                 jk_log(l, JK_LOG_INFO,
                        "Backend connection aborted or network problems");
                 JK_TRACE_EXIT(l);
-                return JK_CLIENT_ERROR;
+                return JK_SERVER_ERROR;
             }
             if (r->flush && r->flush_packets)
                 r->flush(r);
@@ -1617,6 +1617,17 @@
             JK_TRACE_EXIT(l);
             return JK_CLIENT_ERROR;
         }
+        else if (JK_SERVER_ERROR == rc) {
+            /*
+             * Tomcat has stop talking to us, so get out.
+             * We assume this isn't our fault, so just a normal exit.
+             * In most (all?)  cases, the ajp13_endpoint::reuse will still be
+             * false here, so this will be functionally the same as an
+             * un-recoverable error.  We just won't log it as such.
+             */
+            JK_TRACE_EXIT(l);
+            return JK_SERVER_ERROR;
+        }
         else if (rc < 0) {
             JK_TRACE_EXIT(l);
             return (JK_FALSE);  /* XXX error */
@@ -1726,7 +1737,24 @@
                 return JK_TRUE;
             }
 
-            if (err != JK_CLIENT_ERROR) {
+            if (err == JK_CLIENT_ERROR) {
+                *is_error = JK_HTTP_BAD_REQUEST;
+                jk_log(l, JK_LOG_INFO,
+                       "Receiving from tomcat failed, "
+                       "because of client error "
+                       "without recovery in send loop %d", i);
+                JK_TRACE_EXIT(l);
+                return JK_CLIENT_ERROR;
+            }
+            else if (err == JK_SERVER_ERROR) {
+                *is_error = JK_HTTP_SERVER_ERROR;
+                jk_log(l, JK_LOG_INFO,
+                       "Sending to tomcat failed, "
+                       "without recovery in send loop %d", i);
+                JK_TRACE_EXIT(l);
+                return JK_SERVER_ERROR;
+            }
+            else {
                 /* if we can't get reply, check if no recover flag was set
                  * if is_recoverable_error is cleared, we have started
                  * receiving upload data and we must consider that
@@ -1747,15 +1775,6 @@
                 if (i >= JK_RETRIES) {
                     jk_sleep(JK_SLEEP_DEF);
                 }
-            }
-            else {
-                *is_error = JK_HTTP_BAD_REQUEST;
-                jk_log(l, JK_LOG_INFO,
-                       "Receiving from tomcat failed, "
-                       "because of client error "
-                       "without recovery in send loop %d", i);
-                JK_TRACE_EXIT(l);
-                return JK_CLIENT_ERROR;
             }
         }
         if (err == JK_CLIENT_ERROR) {

Modified: tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c
URL: 
http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c?rev=438828&r1=438827&r2=438828&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_lb_worker.c Thu Aug 31 00:29:25 
2006
@@ -759,10 +759,27 @@
                         jk_shm_unlock();
                     rc = JK_TRUE;
                 }
-                else if (service_stat == JK_FALSE) {
+                else if (service_stat == JK_CLIENT_ERROR) {
+                    /*
+                    * Client error !!!
+                    * Since this is bad request do not fail over.
+                    */
+                    rec->s->errors++;
+                    rec->s->state = JK_LB_STATE_OK;
+                    rec->s->error_time = 0;
+                    if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
+                        jk_shm_unlock();
+                    jk_log(l, JK_LOG_INFO,
+                           "unrecoverable error %d, request failed."
+                           " Client failed in the middle of request,"
+                           " we can't recover to another instance.",
+                           is_service_error);
+                    *is_error = is_service_error;
+                    rc = JK_CLIENT_ERROR;
+                }
+                else {
                     /*
                     * Service failed !!!
-                    *
                     * Time for fault tolerance (if possible)...
                     */
 
@@ -788,28 +805,6 @@
                         jk_log(l, JK_LOG_INFO,
                                "service failed, worker %s is in error state",
                                rec->s->name);
-                }
-                else if (service_stat == JK_CLIENT_ERROR) {
-                    /*
-                    * Client error !!!
-                    * Since this is bad request do not fail over.
-                    */
-                    rec->s->errors++;
-                    rec->s->state = JK_LB_STATE_OK;
-                    rec->s->error_time = 0;
-                    if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
-                        jk_shm_unlock();
-                    jk_log(l, JK_LOG_INFO,
-                           "unrecoverable error %d, request failed."
-                           " Client failed in the middle of request,"
-                           " we can't recover to another instance.",
-                           is_service_error);
-                    *is_error = is_service_error;
-                    rc = JK_CLIENT_ERROR;
-                }
-                else {
-                    if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
-                        jk_shm_unlock();
                 }
             }
             if ( rc == -1 ) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to