Bug 39785

Summary: Status code 408 (Request Timeout) is not logged
Product: Apache httpd-2 Reporter: Nobutaka Mantani <nobutaka>
Component: CoreAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: RESOLVED LATER    
Severity: normal CC: mark
Priority: P2 Keywords: FixedInTrunk, MassUpdate
Version: 2.2.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Prevent excessive 408 log entries when KeepAlive is on

Description Nobutaka Mantani 2006-06-12 10:34:10 UTC
With Apache 1.3.x, status code 408 is logged to access log when an HTTP request
isn't sent within a timeout period. But this function is lost in Apache 2.x.

This function is useful for detecting connection flood attack and identifying
the attacker's IP address. The following patch for Apache 2.2.2 enables it (also
applicable to 2.0.58).

--- server/protocol.c.orig	Wed Jun  7 15:41:12 2006
+++ server/protocol.c	Wed Jun  7 20:45:40 2006
@@ -899,6 +899,13 @@
             return r;
         }
 
+        if (r->status == HTTP_REQUEST_TIME_OUT) {
+            ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
+            ap_run_log_transaction(r);
+            apr_brigade_destroy(tmp_bb);
+            return r;
+        }
+
         apr_brigade_destroy(tmp_bb);
         return NULL;
     }
Comment 1 Dan Poirier 2009-10-01 12:33:16 UTC
Fix committed to trunk as r820760

The fix includes the original patch (slightly modified for current trunk code), and a contribution from Stefan Fritsch to make sure a timeout reading the request gets treated as a 408 and not a 400.
Comment 2 Mark Montague 2010-03-05 03:57:21 UTC
Created attachment 25086 [details]
Prevent excessive 408 log entries when KeepAlive is on

When KeepAlive is on, the original patch results in a log entry for every connection, reporting when the keepalive times out.  This results in a large number of 408 status codes in the logs, one for each legitimate connection.  The attached patch (also included below) prevents keepalive-related 408 status codes from being logged while still logging 408 status codes for non-keepalive connections, header timeouts (regardless of whether keepalive is enabled), and so on.

diff -up httpd-2.3.5-alpha/server/protocol.c.keepalivequiet httpd-2.3.5-alpha/server/protocol.c
--- httpd-2.3.5-alpha/server/protocol.c.keepalivequiet  2010-03-04 19:50:04.321471001 -0500
+++ httpd-2.3.5-alpha/server/protocol.c 2010-03-04 21:33:52.657724234 -0500
@@ -923,7 +923,12 @@ request_rec *ap_read_request(conn_rec *c
         }
         else if (r->status == HTTP_REQUEST_TIME_OUT) {
             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
-            ap_run_log_transaction(r);
+            csd = ap_get_module_config(conn->conn_config, &core_module);
+            apr_socket_timeout_get(csd, &cur_timeout);
+            if (conn->keepalive != AP_CONN_KEEPALIVE 
+                || cur_timeout != conn->base_server->keep_alive_timeout) {
+                ap_run_log_transaction(r);
+            }
             apr_brigade_destroy(tmp_bb);
             goto traceout;
         }
Comment 3 Ruediger Pluem 2010-03-05 07:38:40 UTC
(In reply to comment #2)
> Created an attachment (id=25086) [details]
> Prevent excessive 408 log entries when KeepAlive is on

Thanks for the observation. Fixed slightly different in r919323.
Comment 4 Graham Poulter 2011-11-11 06:22:26 UTC
>> Created an attachment (id=25086) [details]
>> Prevent excessive 408 log entries when KeepAlive is on

> Thanks for the observation. Fixed slightly different in r919323.

r919323 is still leaving a lot of 408 errors in Apache logs when Apache is running behind an Amazon Elastic Load Balancer: see https://forums.aws.amazon.com/thread.jspa?messageID=292085&#292085

Patch of r919323 for reference:

--- httpd/httpd/trunk/server/protocol.c	2010/03/05 07:30:17	919322
+++ httpd/httpd/trunk/server/protocol.c	2010/03/05 07:37:15	919323
@@ -923,7 +923,9 @@
         }
         else if (r->status == HTTP_REQUEST_TIME_OUT) {
             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
-            ap_run_log_transaction(r);
+            if (!r->connection->keepalives) {
+                ap_run_log_transaction(r);
+            }
             apr_brigade_destroy(tmp_bb);
             goto traceout;
         }


I believe !r->connection->keepalives is failing to filter out load balancer connections.
Comment 5 Jonathan Sabo 2011-11-15 00:43:28 UTC
This is definitely still an issue behind Amazon ELB's...   I'm getting lots of 408 status codes in my logs.
Comment 6 Eric Covener 2011-11-15 01:16:33 UTC
What exactly?
Comment 7 William A. Rowe Jr. 2018-11-07 21:09:49 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.