-*- coding: utf-8 -*-
Changes with Apache 2.5.0
+ *) mod_http2: changed all AP_DEBUG_ASSERT to ap_assert to have them
+ available also in normal deployments. [Stefan Eissing]
+
*) mpm_unix: Apache fails to start if previously crashed then restarted with
the same PID (e.g. in container). PR 60261.
[Val <valentin.bremond gmail.com>, Yann Ylavic]
APLOGNO(03384) "h2_beam(%d-%s): emitted bucket not "
"in hold, n=%d", beam->id, beam->tag,
(int)proxy->n);
- AP_DEBUG_ASSERT(!proxy->bred);
+ ap_assert(!proxy->bred);
}
}
/* notify anyone waiting on space to become available */
}
static void beam_set_red_pool(h2_bucket_beam *beam, apr_pool_t *pool);
+static void beam_set_green_pool(h2_bucket_beam *beam, apr_pool_t *pool);
+
+static apr_status_t beam_green_cleanup(void *data)
+{
+ h2_bucket_beam *beam = data;
+
+ if (beam->green) {
+ apr_brigade_destroy(beam->green);
+ beam->green = NULL;
+ }
+ beam->green_pool = NULL;
+ return APR_SUCCESS;
+}
+
+static void beam_set_green_pool(h2_bucket_beam *beam, apr_pool_t *pool)
+{
+ if (beam->green_pool != pool) {
+ if (beam->green_pool) {
+ apr_pool_cleanup_kill(beam->green_pool, beam, beam_green_cleanup);
+ }
+ beam->green_pool = pool;
+ if (beam->green_pool) {
+ apr_pool_pre_cleanup_register(beam->green_pool, beam, beam_green_cleanup);
+ }
+ }
+}
static apr_status_t beam_red_cleanup(void *data)
{
}
h2_blist_cleanup(&beam->purge);
h2_blist_cleanup(&beam->hold);
- beam_set_red_pool(beam, NULL);
-
+ beam->red_pool = NULL;
return APR_SUCCESS;
}
apr_status_t status;
beam_close(beam);
+ if (beam->green_pool) {
+ apr_pool_cleanup_kill(beam->green_pool, beam, beam_green_cleanup);
+ status = beam_green_cleanup(beam);
+ }
+
if (beam->red_pool) {
+ apr_pool_cleanup_kill(beam->red_pool, beam, beam_red_cleanup);
status = beam_red_cleanup(beam);
}
- return APR_SUCCESS;
+ return status;
}
apr_status_t h2_beam_destroy(h2_bucket_beam *beam)
return beam->aborted? APR_ECONNABORTED : APR_SUCCESS;
}
-apr_status_t h2_beam_shutdown(h2_bucket_beam *beam, apr_read_type_e block,
- int clear_buffers)
+apr_status_t h2_beam_wait_empty(h2_bucket_beam *beam, apr_read_type_e block)
{
apr_status_t status;
h2_beam_lock bl;
if ((status = enter_yellow(beam, &bl)) == APR_SUCCESS) {
- if (clear_buffers) {
- r_purge_reds(beam);
- h2_blist_cleanup(&beam->red);
- if (!bl.mutex && beam->green) {
- /* not protected, may process green in red call */
- apr_brigade_destroy(beam->green);
- beam->green = NULL;
- }
- }
- beam_close(beam);
-
- while (status == APR_SUCCESS
- && (!H2_BPROXY_LIST_EMPTY(&beam->proxies)
- || (beam->green && !APR_BRIGADE_EMPTY(beam->green)))) {
+ while (status == APR_SUCCESS
+ && !H2_BLIST_EMPTY(&beam->red)
+ && !H2_BPROXY_LIST_EMPTY(&beam->proxies)) {
if (block == APR_NONBLOCK_READ || !bl.mutex) {
status = APR_EAGAIN;
break;
}
/* transfer enough buckets from our green brigade, if we have one */
+ beam_set_green_pool(beam, bb->p);
while (beam->green
&& !APR_BRIGADE_EMPTY(beam->green)
&& (readbytes <= 0 || remain >= 0)) {
return has_proxies;
}
-int h2_beam_closed(h2_bucket_beam *beam)
-{
- return beam->closed;
-}
-
int h2_beam_was_received(h2_bucket_beam *beam)
{
int happend = 0;
* Care needs to be taken when terminating the beam. The beam registers at
* the pool it was created with and will cleanup after itself. However, if
* received buckets do still exist, already freed memory might be accessed.
- * The beam does a AP_DEBUG_ASSERT on this condition.
+ * The beam does a assertion on this condition.
*
* The proper way of shutting down a beam is to first make sure there are no
* more green buckets out there, then cleanup the beam to purge eventually
apr_bucket_brigade *green;
h2_bproxy_list proxies;
apr_pool_t *red_pool;
+ apr_pool_t *green_pool;
apr_size_t max_buf_size;
apr_interval_time_t timeout;
apr_read_type_e block,
apr_off_t readbytes);
-/**
- * Determine if beam is closed. May still contain buffered data.
- *
- * Call from red or green side.
- */
-int h2_beam_closed(h2_bucket_beam *beam);
-
/**
* Determine if beam is empty.
*
*
* Call from the red side only.
*/
-apr_status_t h2_beam_shutdown(h2_bucket_beam *beam, apr_read_type_e block,
- int clear_buffers);
+apr_status_t h2_beam_wait_empty(h2_bucket_beam *beam, apr_read_type_e block);
void h2_beam_mutex_set(h2_bucket_beam *beam,
h2_beam_mutex_enter m_enter,
{
h2_config *cfg = (h2_config *)ap_get_module_config(s->module_config,
&http2_module);
- AP_DEBUG_ASSERT(cfg);
+ ap_assert(cfg);
return cfg;
}
conn_rec *c;
void *cfg;
- AP_DEBUG_ASSERT(master);
+ ap_assert(master);
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, master,
"h2_conn(%ld): create slave", master->id);
return APR_SUCCESS;
}
- AP_DEBUG_ASSERT(b->length <= (io->ssize - io->slen));
+ ap_assert(b->length <= (io->ssize - io->slen));
if (APR_BUCKET_IS_FILE(b)) {
apr_bucket_file *f = (apr_bucket_file *)b->data;
apr_file_t *fd = f->fd;
static h2_ctx *h2_ctx_create(const conn_rec *c)
{
h2_ctx *ctx = apr_pcalloc(c->pool, sizeof(h2_ctx));
- AP_DEBUG_ASSERT(ctx);
+ ap_assert(ctx);
ap_set_module_config(c->conn_config, &http2_module, ctx);
h2_ctx_server_set(ctx, c->base_server);
return ctx;
void h2_ctx_clear(const conn_rec *c)
{
- AP_DEBUG_ASSERT(c);
+ ap_assert(c);
ap_set_module_config(c->conn_config, &http2_module, NULL);
}
ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, f->r,
"h2_task(%s): request filter, exp=%d", task->id, r->expecting_100);
- if (!task->input.chunked) {
+ if (!task->request->chunked) {
status = ap_get_brigade(f->next, bb, mode, block, readbytes);
/* pipe data through, just take care of trailers */
for (b = APR_BRIGADE_FIRST(bb);
* This allow recursive entering of the mutex from the saem thread,
* which is what we need in certain situations involving callbacks
*/
- AP_DEBUG_ASSERT(m);
+ ap_assert(m);
apr_threadkey_private_get(&mutex, thread_lock);
if (mutex == m->lock) {
*pacquired = 0;
return APR_SUCCESS;
}
- AP_DEBUG_ASSERT(m->lock);
+ ap_assert(m->lock);
status = apr_thread_mutex_lock(m->lock);
*pacquired = (status == APR_SUCCESS);
if (*pacquired) {
/* repeat until empty */
}
h2_ihash_clear(m->spurge);
- AP_DEBUG_ASSERT(h2_ihash_empty(m->spurge));
+ ap_assert(h2_ihash_empty(m->spurge));
}
}
static void h2_mplx_destroy(h2_mplx *m)
{
- AP_DEBUG_ASSERT(m);
+ ap_assert(m);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, m->c,
"h2_mplx(%ld): destroy, tasks=%d",
m->id, (int)h2_ihash_count(m->tasks));
apr_status_t status = APR_SUCCESS;
apr_allocator_t *allocator = NULL;
h2_mplx *m;
- AP_DEBUG_ASSERT(conf);
+ ap_assert(conf);
status = apr_allocator_create(&allocator);
if (status != APR_SUCCESS) {
{
conn_rec *slave = NULL;
int reuse_slave = 0;
- apr_status_t status;
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, m->c,
"h2_task(%s): destroy", task->id);
}
}
- /* The pool is cleared/destroyed which also closes all
- * allocated file handles. Give this count back to our
- * file handle pool. */
if (task->output.beam) {
- m->tx_handles_reserved +=
- h2_beam_get_files_beamed(task->output.beam);
h2_beam_on_produced(task->output.beam, NULL, NULL);
- status = h2_beam_shutdown(task->output.beam, APR_NONBLOCK_READ, 1);
- if (status != APR_SUCCESS){
- ap_log_cerror(APLOG_MARK, APLOG_WARNING, status, m->c,
- APLOGNO(03385) "h2_task(%s): output shutdown "
- "incomplete, beam empty=%d, holds proxies=%d",
- task->id,
- h2_beam_empty(task->output.beam),
- h2_beam_holds_proxies(task->output.beam));
- }
+ ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, m->c,
+ APLOGNO(03385) "h2_task(%s): destroy "
+ "output beam empty=%d, holds proxies=%d",
+ task->id,
+ h2_beam_empty(task->output.beam),
+ h2_beam_holds_proxies(task->output.beam));
}
slave = task->c;
/* Remove mutex after, so that abort still finds cond to signal */
h2_beam_mutex_set(stream->input, NULL, NULL, NULL);
}
+ if (stream->output) {
+ m->tx_handles_reserved += h2_beam_get_files_beamed(stream->output);
+ }
h2_stream_cleanup(stream);
task = h2_ihash_get(m->tasks, stream->id);
while (!h2_ihash_iter(m->streams, stream_done_iter, m)) {
/* iterate until all streams have been removed */
}
- AP_DEBUG_ASSERT(h2_ihash_empty(m->streams));
+ ap_assert(h2_ihash_empty(m->streams));
if (!h2_ihash_empty(m->shold)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, m->c,
m->id, (int)h2_ihash_count(m->tasks));
h2_ihash_iter(m->tasks, task_print, m);
}
- AP_DEBUG_ASSERT(h2_ihash_empty(m->shold));
+ ap_assert(h2_ihash_empty(m->shold));
if (!h2_ihash_empty(m->spurge)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, m->c,
"h2_mplx(%ld): 3. release_join %d streams to purge",
{
int acquired;
- AP_DEBUG_ASSERT(m);
if (!m->aborted && enter_mutex(m, &acquired) == APR_SUCCESS) {
m->aborted = 1;
h2_ngn_shed_abort(m->ngn_shed);
apr_status_t status = APR_SUCCESS;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, m->c,
"h2_mplx(%ld-%d): marking stream as done.",
h2_stream *s = NULL;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((enter_mutex(m, &acquired)) == APR_SUCCESS) {
s = h2_ihash_get(m->streams, id);
leave_mutex(m, acquired);
h2_stream *stream;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
stream = h2_ihash_get(m->streams, beam->id);
if (stream) {
apr_status_t status;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (m->aborted) {
status = APR_ECONNABORTED;
apr_status_t status;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (m->aborted) {
status = APR_ECONNABORTED;
apr_status_t status;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (m->aborted) {
status = APR_ECONNABORTED;
int do_registration = 0;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (m->aborted) {
status = APR_ECONNABORTED;
apr_status_t status;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (m->aborted) {
*has_more = 0;
h2_stream *stream;
size_t i, n;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, m->c,
"h2_mplx(%ld): dispatch events", m->id);
apr_status_t status;
int acquired;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
h2_stream *s = h2_ihash_get(m->streams, stream_id);
if (s) {
apr_status_t status;
int acquired, waiting = 1;
- AP_DEBUG_ASSERT(m);
if ((status = enter_mutex(m, &acquired)) == APR_SUCCESS) {
if (h2_ihash_empty(m->streams)) {
waiting = 0;
"h2_ngn_shed(%ld): create engine %s (%s)",
shed->c->id, newngn->id, newngn->type);
if (status == APR_SUCCESS) {
- AP_DEBUG_ASSERT(task->engine == NULL);
+ ap_assert(task->engine == NULL);
newngn->task = task;
task->engine = newngn;
task->assigned = newngn;
{
h2_ngn_entry *entry;
- AP_DEBUG_ASSERT(ngn);
+ ap_assert(ngn);
*pr = NULL;
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, shed->c, APLOGNO(03396)
"h2_ngn_shed(%ld): pull task for engine %s, shutdown=%d",
apr_status_t status = APR_SUCCESS;
const char *err = msg;
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
if (!err && reason) {
err = nghttp2_strerror(reason);
}
h2_proxy_ngheader *ngh;
size_t n;
- AP_DEBUG_ASSERT(req);
- AP_DEBUG_ASSERT(req->scheme);
- AP_DEBUG_ASSERT(req->authority);
- AP_DEBUG_ASSERT(req->path);
- AP_DEBUG_ASSERT(req->method);
+ ap_assert(req);
+ ap_assert(req->scheme);
+ ap_assert(req->authority);
+ ap_assert(req->path);
+ ap_assert(req->method);
n = 4;
apr_table_do(count_header, &n, req->headers, NULL);
req->authority = authority;
req->path = path;
- AP_DEBUG_ASSERT(req->scheme);
- AP_DEBUG_ASSERT(req->authority);
- AP_DEBUG_ASSERT(req->path);
- AP_DEBUG_ASSERT(req->method);
+ ap_assert(req->scheme);
+ ap_assert(req->authority);
+ ap_assert(req->path);
+ ap_assert(req->method);
x.pool = pool;
x.headers = req->headers;
static void h2_session_destroy(h2_session *session)
{
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
h2_ihash_clear(session->streams);
if (session->mplx) {
{
apr_status_t status;
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
if (!session->local.accepting) {
return APR_SUCCESS;
}
{
apr_status_t status = APR_SUCCESS;
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
if (session->local.shutdown) {
return APR_SUCCESS;
}
size_t slen;
int win_size;
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
/* Start the conversation by submitting our SETTINGS frame */
*rv = 0;
if (session->r) {
int eos = 0;
apr_status_t status;
h2_stream *stream;
- AP_DEBUG_ASSERT(session);
+ ap_assert(session);
/* The session wants to send more DATA for the stream. We need
* to find out how much of the requested length we can send without
h2_stream *stream = ctx;
apr_status_t status;
+ ap_assert(stream->can_be_cleaned);
if (stream->files) {
apr_file_t *file;
int i;
void h2_stream_cleanup(h2_stream *stream)
{
- AP_DEBUG_ASSERT(stream);
+ apr_status_t status;
+
+ ap_assert(stream);
if (stream->out_buffer) {
+ /* remove any left over output buckets that may still have
+ * references into request pools */
apr_brigade_cleanup(stream->out_buffer);
}
- if (stream->input) {
- apr_status_t status;
- status = h2_beam_shutdown(stream->input, APR_NONBLOCK_READ, 1);
- if (status == APR_EAGAIN) {
- ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, stream->session->c,
- "h2_stream(%ld-%d): wait on input shutdown",
- stream->session->id, stream->id);
- status = h2_beam_shutdown(stream->input, APR_BLOCK_READ, 1);
- ap_log_cerror(APLOG_MARK, APLOG_TRACE2, status, stream->session->c,
- "h2_stream(%ld-%d): input shutdown returned",
- stream->session->id, stream->id);
- }
+ h2_beam_abort(stream->input);
+ status = h2_beam_wait_empty(stream->input, APR_NONBLOCK_READ);
+ if (status == APR_EAGAIN) {
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, stream->session->c,
+ "h2_stream(%ld-%d): wait on input drain",
+ stream->session->id, stream->id);
+ status = h2_beam_wait_empty(stream->input, APR_BLOCK_READ);
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE2, status, stream->session->c,
+ "h2_stream(%ld-%d): input drain returned",
+ stream->session->id, stream->id);
}
}
void h2_stream_destroy(h2_stream *stream)
{
- AP_DEBUG_ASSERT(stream);
+ ap_assert(stream);
+ ap_assert(!h2_mplx_stream_get(stream->session->mplx, stream->id));
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, stream->session->c,
"h2_stream(%ld-%d): destroy",
stream->session->id, stream->id);
+ stream->can_be_cleaned = 1;
if (stream->pool) {
apr_pool_destroy(stream->pool);
}
const char *name, size_t nlen,
const char *value, size_t vlen)
{
- AP_DEBUG_ASSERT(stream);
+ ap_assert(stream);
if (!stream->has_response) {
if (name[0] == ':') {
h2_stream_pri_cmp *cmp, void *ctx)
{
apr_status_t status = APR_EINVAL;
- AP_DEBUG_ASSERT(stream);
- AP_DEBUG_ASSERT(stream->session);
- AP_DEBUG_ASSERT(stream->session->mplx);
+ ap_assert(stream);
+ ap_assert(stream->session);
+ ap_assert(stream->session->mplx);
if (!stream->scheduled) {
if (eos) {
apr_status_t h2_stream_close_input(h2_stream *stream)
{
conn_rec *c = stream->session->c;
- apr_status_t status = APR_SUCCESS, rv;
+ apr_status_t status;
+ apr_bucket_brigade *tmp;
+ apr_bucket *b;
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, stream->session->c,
"h2_stream(%ld-%d): closing input",
return APR_ECONNRESET;
}
- if (!stream->input) {
- h2_beam_create(&stream->input, stream->pool, stream->id, "input", 0);
- }
-
+ tmp = apr_brigade_create(stream->pool, c->bucket_alloc);
if (stream->trailers && !apr_is_empty_table(stream->trailers)) {
h2_headers *r = h2_headers_create(HTTP_OK, stream->trailers,
NULL, stream->pool);
- apr_bucket *b = h2_bucket_headers_create(c->bucket_alloc, r);
- apr_bucket_brigade *tmp;
-
- tmp = apr_brigade_create(stream->pool, c->bucket_alloc);
+ b = h2_bucket_headers_create(c->bucket_alloc, r);
APR_BRIGADE_INSERT_TAIL(tmp, b);
- status = h2_beam_send(stream->input, tmp, APR_BLOCK_READ);
- apr_brigade_destroy(tmp);
-
stream->trailers = NULL;
}
- close_input(stream);
- rv = h2_beam_close(stream->input);
- return status ? status : rv;
+ b = apr_bucket_eos_create(c->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(tmp, b);
+ status = h2_beam_send(stream->input, tmp, APR_BLOCK_READ);
+ apr_brigade_destroy(tmp);
+ return status;
}
apr_status_t h2_stream_write_data(h2_stream *stream,
apr_status_t status = APR_SUCCESS;
apr_bucket_brigade *tmp;
- AP_DEBUG_ASSERT(stream);
+ ap_assert(stream);
if (!stream->input) {
return APR_EOF;
}
unsigned int started : 1; /* stream has started processing */
unsigned int has_response : 1; /* response headers are known */
unsigned int push_policy; /* which push policy to use for this request */
+ unsigned int can_be_cleaned : 1; /* stream pool can be cleaned */
apr_off_t out_data_frames; /* # of DATA frames sent */
apr_off_t out_data_octets; /* # of DATA octets (payload) sent */
void h2_stream_destroy(h2_stream *stream);
/**
- * Removes stream from h2_session and destroys it.
+ * Cleanup references into requst processing.
*
* @param stream the stream to cleanup
*/
apr_status_t h2_task_do(h2_task *task, apr_thread_t *thread, int worker_id)
{
- AP_DEBUG_ASSERT(task);
+ ap_assert(task);
if (task->c->master) {
/* Each conn_rec->id is supposed to be unique at a point in time. Since
task->c->id = (task->c->master->id << free_bits)^slave_id;
}
- task->input.chunked = task->request->chunked;
task->input.bb = apr_brigade_create(task->pool, task->c->bucket_alloc);
if (task->request->serialize) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, task->c,
struct {
struct h2_bucket_beam *beam;
- unsigned int chunked : 1;
unsigned int eos : 1;
apr_bucket_brigade *bb;
apr_bucket_brigade *bbchunk;
h2_ngheader *ngh;
size_t n;
- AP_DEBUG_ASSERT(req);
- AP_DEBUG_ASSERT(req->scheme);
- AP_DEBUG_ASSERT(req->authority);
- AP_DEBUG_ASSERT(req->path);
- AP_DEBUG_ASSERT(req->method);
+ ap_assert(req);
+ ap_assert(req->scheme);
+ ap_assert(req->authority);
+ ap_assert(req->path);
+ ap_assert(req->method);
n = 4;
apr_table_do(count_header, &n, req->headers, NULL);
h2_workers *workers;
apr_pool_t *pool;
- AP_DEBUG_ASSERT(s);
- AP_DEBUG_ASSERT(server_pool);
+ ap_assert(s);
+ ap_assert(server_pool);
/* let's have our own pool that will be parent to all h2_worker
* instances we create. This happens in various threads, but always