summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuediger Pluem <rpluem@apache.org>2007-05-01 12:17:30 +0000
committerRuediger Pluem <rpluem@apache.org>2007-05-01 12:17:30 +0000
commit9d24ba2573c9842591d69386c70e52efe02f3723 (patch)
tree3eb469bf4bcb42cf10a4adea813bdf1dfe2e8c12
parent2c91e92953037f3f656202c6e2c549b64faa9e02 (diff)
downloadhttpd-9d24ba2573c9842591d69386c70e52efe02f3723.tar.gz
* Rework the error handling logic to make it more readable.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@534031 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--modules/proxy/mod_proxy_ajp.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/modules/proxy/mod_proxy_ajp.c b/modules/proxy/mod_proxy_ajp.c
index e7c372e500..9811b9a80e 100644
--- a/modules/proxy/mod_proxy_ajp.c
+++ b/modules/proxy/mod_proxy_ajp.c
@@ -127,7 +127,8 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
ap_log_error(APLOG_MARK, APLOG_DEBUG, status,
r->server,
"apr_brigade_flatten failed");
- isok = 0;
+ output_failed = 1;
break;
}
}
@@ -305,7 +306,7 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
*/
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
*/
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
*/
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 @@ static int ap_proxy_ajp_request(apr_pool_t *p, request_rec *r,
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;
}
/*