On 12/17/2005 11:22 PM, Ruediger Pluem wrote:
> 
> On 12/17/2005 06:30 PM, Jim Jagielski wrote:

[..cut..]

> 
> 
>>Even so, I say let's fold this into trunk as is, and
>>then work on abstracting it out.
> 

Done as r357461.
Attached a patch that

- fixes the same problem for mod_proxy_ajp
- puts the common code in proxy_util
- fixes a little return code issue that is related to Justins original patch in 
r354628


Regards

Rüdiger
Index: modules/proxy/mod_proxy_ajp.c
===================================================================
--- modules/proxy/mod_proxy_ajp.c       (Revision 357461)
+++ modules/proxy/mod_proxy_ajp.c       (Arbeitskopie)
@@ -138,6 +138,7 @@
     int havebody = 1;
     int isok = 1;
     apr_off_t bb_len;
+    int data_sent = 0;
 #ifdef FLUSHING_BANDAID
     apr_int32_t conn_poll_fd;
     apr_pollfd_t *conn_poll;
@@ -348,6 +349,7 @@
                                       "proxy: error processing body");
                         isok = 0;
                     }
+                    data_sent = 1;
                     apr_brigade_cleanup(output_brigade);
                 }
                 else {
@@ -363,6 +365,7 @@
                                   "proxy: error processing body");
                     isok = 0;
                 }
+                data_sent = 1;
                 break;
             default:
                 isok = 0;
@@ -400,8 +403,6 @@
     }
     apr_brigade_destroy(input_brigade);
 
-    apr_brigade_destroy(output_brigade);
-
     if (status != APR_SUCCESS) {
         /* We had a failure: Close connection to backend */
         conn->close++;
@@ -409,9 +410,20 @@
                      "proxy: send body failed to %pI (%s)",
                      conn->worker->cp->addr,
                      conn->worker->hostname);
+        /*
+         * If we already send data, signal a broken backend connection
+         * upwards in the chain.
+         */
+        if (data_sent) {
+            ap_proxy_backend_broke(r, output_brigade);
+            /* Return DONE to avoid error messages being added to the stream */
+            return DONE;
+        }
         return HTTP_SERVICE_UNAVAILABLE;
     }
 
+    apr_brigade_destroy(output_brigade);
+
     /* 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,
Index: modules/proxy/proxy_util.c
===================================================================
--- modules/proxy/proxy_util.c  (Revision 357461)
+++ modules/proxy/proxy_util.c  (Arbeitskopie)
@@ -2129,3 +2129,18 @@
     lb_workers_limit = proxy_lb_workers + PROXY_DYNAMIC_BALANCER_LIMIT;
     return lb_workers_limit;
 }
+
+PROXY_DECLARE(apr_status_t) ap_proxy_backend_broke(request_rec *r,
+                                                   apr_bucket_brigade *brigade)
+{
+    apr_bucket *e;
+    conn_rec *c = r->connection;
+
+    r->no_cache = 1;
+    e = ap_bucket_error_create(HTTP_BAD_GATEWAY, NULL, c->pool,
+                               c->bucket_alloc);
+    APR_BRIGADE_INSERT_TAIL(brigade, e);
+    e = apr_bucket_eos_create(c->bucket_alloc);
+    APR_BRIGADE_INSERT_TAIL(brigade, e);
+    return ap_pass_brigade(r->output_filters, brigade);
+}
Index: modules/proxy/mod_proxy_http.c
===================================================================
--- modules/proxy/mod_proxy_http.c      (Revision 357461)
+++ modules/proxy/mod_proxy_http.c      (Arbeitskopie)
@@ -1199,6 +1199,7 @@
                            * are being read. */
     int pread_len = 0;
     apr_table_t *save_table;
+    int backend_broke = 0;
 
     bb = apr_brigade_create(p, c->bucket_alloc);
 
@@ -1485,13 +1486,8 @@
                          */
                         ap_log_cerror(APLOG_MARK, APLOG_ERR, rv, c,
                                       "proxy: error reading response");
-                        r->no_cache = 1;
-                        e = ap_bucket_error_create(HTTP_BAD_GATEWAY,  NULL,
-                                                   c->pool, c->bucket_alloc);
-                        APR_BRIGADE_INSERT_TAIL(bb, e);
-                        e = apr_bucket_eos_create(c->bucket_alloc);
-                        APR_BRIGADE_INSERT_TAIL(bb, e);
-                        ap_pass_brigade(r->output_filters, bb);
+                        ap_proxy_backend_broke(r, bb);
+                        backend_broke = 1;
                         backend->close = 1;
                         break;
                     }
@@ -1559,7 +1555,7 @@
     } while (interim_response);
 
     /* If our connection with the client is to be aborted, return DONE. */
-    if (c->aborted) {
+    if (c->aborted || backend_broke) {
         return DONE;
     }
 
Index: modules/proxy/mod_proxy.h
===================================================================
--- modules/proxy/mod_proxy.h   (Revision 357461)
+++ modules/proxy/mod_proxy.h   (Arbeitskopie)
@@ -669,6 +669,16 @@
 PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
                                               proxy_conn_rec *conn,
                                               conn_rec *c, server_rec *s);
+/**
+ * Signal the upstream chain that the connection to the backend broke in the
+ * middle of the response. This is done by sending an error bucket with
+ * status HTTP_BAD_GATEWAY and an EOS bucket up the filter chain.
+ * @param r       current request record of client request
+ * @param brigade The brigade that is sent through the output filter chain
+ * @return        The return code of ap_pass_brigade(r->output_filters, 
brigade)
+ */
+PROXY_DECLARE(apr_status_t) ap_proxy_backend_broke(request_rec *r,
+                                                   apr_bucket_brigade 
*brigade);
 
 /* Scoreboard */
 #if MODULE_MAGIC_NUMBER_MAJOR > 20020903

Reply via email to