From: Greg Ames Date: Mon, 9 Dec 2002 22:19:26 +0000 (+0000) Subject: core_output_filter: re-instate the deferred_write pool patch so we don't X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28912b53f4352a3d37f12a2dd26854eb8f362db1;p=apache core_output_filter: re-instate the deferred_write pool patch so we don't leak fd's until the end of a keepalive connection. Thanks to: Jeff Trawick for the original concept Sander Striker for the mmap ring idea Cliff Woolley for implementing the above change git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97824 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 3b6c0d311b..1514f33b58 100644 --- a/CHANGES +++ b/CHANGES @@ -1,11 +1,17 @@ Changes with Apache 2.1.0-dev + + [Remove entries to the current 2.0 section below, when backported] + + *) Fix a bug where we leak fd's until the end of a keepalive + connection, which may result in: + (24)Too many open files: file permissions deny server access + especially on threaded servers. [Greg Ames] + *) If an httpd.conf has commented out AddModule directives, apxs -i -a will add an un-commented AddModule directive for the new module, which breaks the config. PR: 11212 [Joe Orton] - [Remove entries to the current 2.0 section below, when backported] - *) Fix mod_proxy handling of filtered input bodies. [Justin Erenkrantz] *) Don't remove the Content-Length from responses in mod_proxy @@ -143,11 +149,6 @@ Changes with Apache 2.0.44 once per worker, indicating that the CacheRoot needs to be set. [Paul J. Reder] - *) Fix a bug where we keep files open until the end of a - keepalive connection, which can result in: - (24)Too many open files: file permissions deny server access - especially on threaded servers. [Greg Ames, Jeff Trawick] - *) Fix a bug in which mod_proxy sent an invalid Content-Length when a proxied URL was invoked as a server-side include within a page generated in response to a form POST. [Brian Pane] diff --git a/server/core.c b/server/core.c index ceb5627f17..18e8e04b30 100644 --- a/server/core.c +++ b/server/core.c @@ -3670,6 +3670,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) core_net_rec *net = f->ctx; core_output_filter_ctx_t *ctx = net->out_ctx; apr_read_type_e eblock = APR_NONBLOCK_READ; + apr_pool_t *input_pool = b->p; if (ctx == NULL) { ctx = apr_pcalloc(c->pool, sizeof(*ctx)); @@ -3924,7 +3925,10 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) } } } - ap_save_brigade(f, &ctx->b, &b, c->pool); + if (!ctx->deferred_write_pool) { + apr_pool_create(&ctx->deferred_write_pool, c->pool); + } + ap_save_brigade(f, &ctx->b, &b, ctx->deferred_write_pool); return APR_SUCCESS; } @@ -3995,6 +3999,30 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b) } apr_brigade_destroy(b); + + /* drive cleanups for resources which were set aside + * this may occur before or after termination of the request which + * created the resource + */ + if (ctx->deferred_write_pool) { + if (more && more->p == ctx->deferred_write_pool) { + /* "more" belongs to the deferred_write_pool, + * which is about to be cleared. + */ + if (APR_BRIGADE_EMPTY(more)) { + more = NULL; + } + else { + /* uh oh... change more's lifetime + * to the input brigade's lifetime + */ + apr_bucket_brigade *tmp_more = more; + more = NULL; + ap_save_brigade(f, &more, &tmp_more, input_pool); + } + } + apr_pool_clear(ctx->deferred_write_pool); + } if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server,