b5595b
diff --git a/modules/generators/mod_cgi.c b/modules/generators/mod_cgi.c
b5595b
index 7808262..38e43d3 100644
b5595b
--- a/modules/generators/mod_cgi.c
b5595b
+++ b/modules/generators/mod_cgi.c
b5595b
@@ -946,6 +946,13 @@ static int cgi_handler(request_rec *r)
b5595b
         if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
b5595b
                                                         APLOG_MODULE_INDEX)))
b5595b
         {
b5595b
+            /* In the case of a timeout reading script output, clear
b5595b
+             * the brigade to avoid a second attempt to read the
b5595b
+             * output. */
b5595b
+            if (ret == HTTP_GATEWAY_TIME_OUT) {
b5595b
+                apr_brigade_cleanup(bb);
b5595b
+            }
b5595b
+
b5595b
             ret = log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
b5595b
 
b5595b
             /*
b5595b
diff --git a/modules/generators/mod_cgid.c b/modules/generators/mod_cgid.c
b5595b
index 56d3524..b1e7dec 100644
b5595b
--- a/modules/generators/mod_cgid.c
b5595b
+++ b/modules/generators/mod_cgid.c
b5595b
@@ -1554,6 +1554,13 @@ static int cgid_handler(request_rec *r)
b5595b
         if ((ret = ap_scan_script_header_err_brigade_ex(r, bb, sbuf,
b5595b
                                                         APLOG_MODULE_INDEX)))
b5595b
         {
b5595b
+            /* In the case of a timeout reading script output, clear
b5595b
+             * the brigade to avoid a second attempt to read the
b5595b
+             * output. */
b5595b
+            if (ret == HTTP_GATEWAY_TIME_OUT) {
b5595b
+                apr_brigade_cleanup(bb);
b5595b
+            }
b5595b
+
b5595b
             ret = log_script(r, conf, ret, dbuf, sbuf, bb, NULL);
b5595b
 
b5595b
             /*