Commit 58764301 authored by Brian Pane's avatar Brian Pane
Browse files

Redesign of request cleanup:

  - A new End-Of-Request bucket is pushed through the output filter
    chain after the last bucket of the response.
  - This bucket gets destroyed by ap_core_output_filter() after the
    buckets in front of it have been sent.
  - The destroy callback of the EOR bucket invokes the access logger
    and frees the request's pool.

With this change, the request logger now runs after the last byte of
the response is _sent_, rather than after the last byte of the response
is _generated_.  This should make the bytes-sent count in the access
log more accurate in cases where the client closes the connection
midway through the sending of the response.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/async-dev@307339 13f79535-47bb-0310-9956-ffa450edef68
parent ceca8bbf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
                                                        -*- coding: utf-8 -*-
Changes in Apache 2.3.0 async-dev R&D branch
  *) Added an End-Of-Request bucket type.  The logging of a request and
     the freeing of its pool are now done when the EOR bucket is destroyed.
     This has the effect of delaying the logging until right after the last
     of the response is sent; ap_core_output_filter() calls the access logger
     indirectly when it destroys the EOR bucket. [Brian Pane]
  *) Rewrite of ap_core_output_filter to do nonblocking writes [Brian Pane]
  *) Added new connection states for handler and write completion
+30 −0
Original line number Diff line number Diff line
@@ -354,6 +354,36 @@ AP_DECLARE(int) ap_location_walk(request_rec *r);
AP_DECLARE(int) ap_directory_walk(request_rec *r);
AP_DECLARE(int) ap_file_walk(request_rec *r);

/** End Of REQUEST (EOR) bucket */
AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eor;

/**
 * Determine if a bucket is an End Of REQUEST (EOR) bucket
 * @param e The bucket to inspect
 * @return true or false
 */
#define AP_BUCKET_IS_EOR(e)         (e->type == &ap_bucket_type_eor)

/**
 * Make the bucket passed in an End Of REQUEST (EOR) bucket
 * @param b The bucket to make into an EOR bucket
 * @param r The request to destroy when this bucket is destroyed
 * @return The new bucket, or NULL if allocation failed
 */
AP_DECLARE(apr_bucket *) ap_bucket_eor_make(apr_bucket *b, request_rec *r);

/**
 * Create a bucket referring to an End Of REQUEST (EOR). This bucket
 * holds a pointer to the request_rec, so that the request can be
 * destroyed right after all of the output has been sent to the client.
 *
 * @param list The freelist from which this bucket should be allocated
 * @param r The request to destroy when this bucket is destroyed
 * @return The new bucket, or NULL if allocation failed
 */
AP_DECLARE(apr_bucket *) ap_bucket_eor_create(apr_bucket_alloc_t *list,
                                              request_rec *r);

#ifdef __cplusplus
}
#endif
+0 −3
Original line number Diff line number Diff line
@@ -143,8 +143,6 @@ static int ap_process_http_async_connection(conn_rec *c)
                 */
                cs->state = CONN_STATE_READ_REQUEST_LINE;
            }

            apr_pool_destroy(r->pool);
        }
        else {   /* ap_read_request failed - client may have closed */
            cs->state = CONN_STATE_LINGER;
@@ -181,7 +179,6 @@ static int ap_process_http_connection(conn_rec *c)
            break;
 
        ap_update_child_status(c->sbh, SERVER_BUSY_KEEPALIVE, r);
        apr_pool_destroy(r->pool);
 
        if (ap_graceful_stop_signalled())
            break;
+11 −1
Original line number Diff line number Diff line
@@ -234,6 +234,8 @@ static void check_pipeline_flush(request_rec *r)
void ap_process_request(request_rec *r)
{
    int access_status;
    apr_bucket_brigade *bb;
    apr_bucket *b;

    /* Give quick handlers a shot at serving the request on the fast
     * path, bypassing all of the other Apache hooks.
@@ -271,6 +273,15 @@ void ap_process_request(request_rec *r)
        ap_die(access_status, r);
    }
    
    /* Send an EOR bucket through the output filter chain.  When
     * this bucket is destroyed, the request will be logged and
     * its pool will be freed
     */
    bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
    b = ap_bucket_eor_create(r->connection->bucket_alloc, r);
    APR_BRIGADE_INSERT_HEAD(bb, b);
    ap_pass_brigade(r->connection->output_filters, bb);

    /*
     * We want to flush the last packet if this isn't a pipelining connection
     * *before* we start into logging.  Suppose that the logging causes a DNS
@@ -280,7 +291,6 @@ void ap_process_request(request_rec *r)
     */
    check_pipeline_flush(r);
    ap_update_child_status(r->connection->sbh, SERVER_BUSY_LOG, r);
    ap_run_log_transaction(r);
    if (ap_extended_status)
        ap_time_process_request(r->connection->sbh, STOP_PREQUEST);
}
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ LTLIBRARY_SOURCES = \
	mpm_common.c util_charset.c util_debug.c util_xml.c \
	util_filter.c util_pcre.c exports.c \
	scoreboard.c error_bucket.c protocol.c core.c request.c provider.c \
	eoc_bucket.c core_filters.c
	eoc_bucket.c eor_bucket.c core_filters.c

TARGETS = delete-exports $(LTLIBRARY_NAME) $(CORE_IMPLIB_FILE) export_vars.h httpd.exp

Loading