httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpl...@apache.org
Subject svn commit: r534031 - /httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c
Date Tue, 01 May 2007 12:17:30 GMT
Author: rpluem
Date: Tue May  1 05:17:30 2007
New Revision: 534031

URL: http://svn.apache.org/viewvc?view=rev&rev=534031
Log:
* Rework the error handling logic to make it more readable.

Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c?view=diff&rev=534031&r1=534030&r2=534031
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy_ajp.c Tue May  1 05:17:30 2007
@@ -127,7 +127,8 @@
     apr_uint16_t size;
     const char *tenc;
     int havebody = 1;
-    int isok = 1;
+    int output_failed = 0;
+    int backend_failed = 0;
     apr_off_t bb_len;
     int data_sent = 0;
     int rv = 0;
@@ -264,7 +265,7 @@
     conn_poll->desc.s = conn->sock;
 
     bufsiz = maxsize;
-    while (isok) {
+    for (;;) {
         switch (result) {
             case CMD_AJP13_GET_BODY_CHUNK:
                 if (havebody) {
@@ -283,7 +284,7 @@
                             ap_log_error(APLOG_MARK, APLOG_DEBUG, status,
                                          r->server,
                                          "ap_get_brigade failed");
-                            isok = 0;
+                            output_failed = 1;
                             break;
                         }
                         bufsiz = maxsize;
@@ -294,7 +295,7 @@
                             ap_log_error(APLOG_MARK, APLOG_DEBUG, status,
                                          r->server,
                                          "apr_brigade_flatten failed");
-                            isok = 0;
+                            output_failed = 1;
                             break;
                         }
                     }
@@ -305,7 +306,7 @@
                     if (status != APR_SUCCESS) {
                         ap_log_error(APLOG_MARK, APLOG_DEBUG, status, r->server,
                                      "ajp_send_data_msg failed");
-                        isok = 0;
+                        backend_failed = 1;
                         break;
                     }
                     conn->worker->s->transferred += bufsiz;
@@ -316,14 +317,14 @@
                      */
                     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                                  "ap_proxy_ajp_request error read after end");
-                    isok = 0;
+                    backend_failed = 1;
                 }
                 break;
             case CMD_AJP13_SEND_HEADERS:
                 /* AJP13_SEND_HEADERS: process them */
                 status = ajp_parse_header(r, conf, conn->data);
                 if (status != APR_SUCCESS) {
-                    isok = 0;
+                    backend_failed = 1;
                 }
                 break;
             case CMD_AJP13_SEND_BODY_CHUNK:
@@ -358,13 +359,13 @@
                                         output_brigade) != APR_SUCCESS) {
                         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                                       "proxy: error processing body");
-                        isok = 0;
+                        output_failed = 1;
                     }
                     data_sent = 1;
                     apr_brigade_cleanup(output_brigade);
                 }
                 else {
-                    isok = 0;
+                    backend_failed = 1;
                 }
                 break;
             case CMD_AJP13_END_RESPONSE:
@@ -374,39 +375,41 @@
                                     output_brigade) != APR_SUCCESS) {
                     ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                                   "proxy: error processing end");
-                    isok = 0;
+                    output_failed = 1;
                 }
                 /* XXX: what about flush here? See mod_jk */
                 data_sent = 1;
                 break;
             default:
-                isok = 0;
+                backend_failed = 1;
                 break;
         }
 
         /*
          * If connection has been aborted by client: Stop working.
          * Nevertheless, we regard our operation so far as a success:
-         * So do not set isok to 0 and set result to CMD_AJP13_END_RESPONSE
+         * So reset output_failed to 0 and set result to CMD_AJP13_END_RESPONSE
          * But: Close this connection to the backend.
          */
         if (r->connection->aborted) {
             conn->close++;
+            output_failed = 0;
             result = CMD_AJP13_END_RESPONSE;
-            break;
         }
 
-        if (!isok)
-            break;
-
-        if (result == CMD_AJP13_END_RESPONSE)
+        /*
+         * We either have finished successfully or we failed.
+         * So bail out
+         */
+        if ((result == CMD_AJP13_END_RESPONSE) || backend_failed
+            || output_failed)
             break;
 
         /* read the response */
         status = ajp_read_header(conn->sock, r, maxsize,
                                  (ajp_msg_t **)&(conn->data));
         if (status != APR_SUCCESS) {
-            isok = 0;
+            backend_failed = 1;
             ap_log_error(APLOG_MARK, APLOG_DEBUG, status, r->server,
                          "ajp_read_header failed");
             break;
@@ -421,9 +424,26 @@
      */
     apr_brigade_cleanup(output_brigade);
 
-    if (! isok) {
+    if (backend_failed || output_failed) {
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                     "proxy: Processing of request failed backend: %i, "
+                     "output: %i", backend_failed, output_failed);
         /* We had a failure: Close connection to backend */
         conn->close++;
+        /* Return DONE to avoid error messages being added to the stream */
+        if (data_sent) {
+            rv = DONE;
+        }
+    }
+    else {
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
+                     "proxy: got response from %pI (%s)",
+                     conn->worker->cp->addr,
+                     conn->worker->hostname);
+        rv = OK;
+    }
+
+    if (backend_failed) {
         ap_log_error(APLOG_MARK, APLOG_ERR, status, r->server,
                      "proxy: dialog to %pI (%s) failed",
                      conn->worker->cp->addr,
@@ -434,8 +454,6 @@
          */
         if (data_sent) {
             ap_proxy_backend_broke(r, output_brigade);
-            /* Return DONE to avoid error messages being added to the stream */
-            rv = DONE;
         } else
             rv = HTTP_SERVICE_UNAVAILABLE;
     }
@@ -457,27 +475,7 @@
 
     apr_brigade_destroy(output_brigade);
 
-    if (rv)
-        return rv;
-
-    /* Nice we have answer to send to the client */
-    if (result == CMD_AJP13_END_RESPONSE && isok) {
-        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
-                     "proxy: got response from %pI (%s)",
-                     conn->worker->cp->addr,
-                     conn->worker->hostname);
-        return OK;
-    }
-
-    ap_log_error(APLOG_MARK, APLOG_ERR, status, r->server,
-                 "proxy: got bad response (%d) from %pI (%s)",
-                 result,
-                 conn->worker->cp->addr,
-                 conn->worker->hostname);
-
-    /* We had a failure: Close connection to backend */
-    conn->close++;
-    return HTTP_SERVICE_UNAVAILABLE;
+    return rv;
 }
 
 /*



Mime
View raw message