Skip to content

Commit

Permalink
v1.0.14, fixed segfault in connection shutdown, added accept-push-pol…
Browse files Browse the repository at this point in the history
…icy support
  • Loading branch information
Stefan Eissing committed Dec 23, 2015
1 parent 19768aa commit ed46bbf
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 250 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v1.0.14
--------------------------------------------------------------------------------
* fixed segfault on connection shutdown

v1.0.13
--------------------------------------------------------------------------------
* reworked connection state handling. Improved scoreboard update (server-status).
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#

AC_PREREQ([2.69])
AC_INIT([mod_http2], [1.0.13], [[email protected]])
AC_INIT([mod_http2], [1.0.14], [[email protected]])

LT_PREREQ([2.2.6])
LT_INIT()
Expand Down
30 changes: 20 additions & 10 deletions mod-h2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@
B25574A01BEB6EFC0058F97B /* h2_workers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = h2_workers.h; sourceTree = "<group>"; };
B25574A21BEB6EFC0058F97B /* h2.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = h2.m4; sourceTree = "<group>"; };
B25574A41BEB6EFC0058F97B /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
B25574A61BEB6EFC0058F97B /* mod_h2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mod_h2.h; sourceTree = "<group>"; };
B25574A71BEB6EFC0058F97B /* mod_http2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = mod_http2.c; sourceTree = "<group>"; };
B256C4BA1ADD5FF10042C760 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
B27BBD2D1A6575C200C58A41 /* README */ = {isa = PBXFileReference; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
B2A6EF2A1A9E3A93005DFC5B /* INSTALL */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = INSTALL; sourceTree = "<group>"; };
B2A6EF2C1A9F2452005DFC5B /* DISCUSS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DISCUSS; sourceTree = "<group>"; };
B2AB9AB71C2ADBE100908DD6 /* h2_filter.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = h2_filter.c; sourceTree = "<group>"; };
B2AB9AB81C2ADBE100908DD6 /* h2_filter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = h2_filter.h; sourceTree = "<group>"; };
B2AB9AB91C2ADBE100908DD6 /* h2_push.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = h2_push.c; sourceTree = "<group>"; };
B2AB9ABA1C2ADBE100908DD6 /* h2_push.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = h2_push.h; sourceTree = "<group>"; };
B2AB9ABB1C2ADBE100908DD6 /* h2_version.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = h2_version.h; sourceTree = "<group>"; };
B2AB9ABC1C2ADBE100908DD6 /* mod_http2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mod_http2.h; sourceTree = "<group>"; };
B2E5D7841AAEEF8C001FD280 /* configure.ac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = configure.ac; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.sh; };
B2E5D7851AAF1D87001FD280 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
B2E5D7861AAF1F4D001FD280 /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; };
Expand Down Expand Up @@ -113,56 +118,61 @@
B255746F1BEB6EFC0058F97B /* h2_bucket_eos.h */,
B25574701BEB6EFC0058F97B /* h2_config.c */,
B25574711BEB6EFC0058F97B /* h2_config.h */,
B25574721BEB6EFC0058F97B /* h2_conn.c */,
B25574741BEB6EFC0058F97B /* h2_conn_io.c */,
B25574731BEB6EFC0058F97B /* h2_conn.h */,
B25574751BEB6EFC0058F97B /* h2_conn_io.h */,
B25574721BEB6EFC0058F97B /* h2_conn.c */,
B25574731BEB6EFC0058F97B /* h2_conn.h */,
B25574761BEB6EFC0058F97B /* h2_ctx.c */,
B25574771BEB6EFC0058F97B /* h2_ctx.h */,
B2AB9AB71C2ADBE100908DD6 /* h2_filter.c */,
B2AB9AB81C2ADBE100908DD6 /* h2_filter.h */,
B25574781BEB6EFC0058F97B /* h2_from_h1.c */,
B25574791BEB6EFC0058F97B /* h2_from_h1.h */,
B255747A1BEB6EFC0058F97B /* h2_h2.c */,
B255747B1BEB6EFC0058F97B /* h2_h2.h */,
B255747C1BEB6EFC0058F97B /* h2_io.c */,
B255747D1BEB6EFC0058F97B /* h2_io.h */,
B255747E1BEB6EFC0058F97B /* h2_io_set.c */,
B255747F1BEB6EFC0058F97B /* h2_io_set.h */,
B255747C1BEB6EFC0058F97B /* h2_io.c */,
B255747D1BEB6EFC0058F97B /* h2_io.h */,
B25574801BEB6EFC0058F97B /* h2_mplx.c */,
B25574811BEB6EFC0058F97B /* h2_mplx.h */,
B25574821BEB6EFC0058F97B /* h2_private.h */,
B2AB9AB91C2ADBE100908DD6 /* h2_push.c */,
B2AB9ABA1C2ADBE100908DD6 /* h2_push.h */,
B25574831BEB6EFC0058F97B /* h2_request.c */,
B25574841BEB6EFC0058F97B /* h2_request.h */,
B25574851BEB6EFC0058F97B /* h2_response.c */,
B25574861BEB6EFC0058F97B /* h2_response.h */,
B25574871BEB6EFC0058F97B /* h2_session.c */,
B25574881BEB6EFC0058F97B /* h2_session.h */,
B25574891BEB6EFC0058F97B /* h2_stream.c */,
B255748A1BEB6EFC0058F97B /* h2_stream.h */,
B255748B1BEB6EFC0058F97B /* h2_stream_set.c */,
B255748C1BEB6EFC0058F97B /* h2_stream_set.h */,
B25574891BEB6EFC0058F97B /* h2_stream.c */,
B255748A1BEB6EFC0058F97B /* h2_stream.h */,
B255748D1BEB6EFC0058F97B /* h2_switch.c */,
B255748E1BEB6EFC0058F97B /* h2_switch.h */,
B255748F1BEB6EFC0058F97B /* h2_task.c */,
B25574901BEB6EFC0058F97B /* h2_task.h */,
B25574911BEB6EFC0058F97B /* h2_task_input.c */,
B25574921BEB6EFC0058F97B /* h2_task_input.h */,
B25574931BEB6EFC0058F97B /* h2_task_output.c */,
B25574941BEB6EFC0058F97B /* h2_task_output.h */,
B25574951BEB6EFC0058F97B /* h2_task_queue.c */,
B25574961BEB6EFC0058F97B /* h2_task_queue.h */,
B255748F1BEB6EFC0058F97B /* h2_task.c */,
B25574901BEB6EFC0058F97B /* h2_task.h */,
B25574971BEB6EFC0058F97B /* h2_to_h1.c */,
B25574981BEB6EFC0058F97B /* h2_to_h1.h */,
B25574991BEB6EFC0058F97B /* h2_util.c */,
B255749A1BEB6EFC0058F97B /* h2_util.h */,
B2AB9ABB1C2ADBE100908DD6 /* h2_version.h */,
B255749C1BEB6EFC0058F97B /* h2_version.h.in */,
B255749D1BEB6EFC0058F97B /* h2_worker.c */,
B255749E1BEB6EFC0058F97B /* h2_worker.h */,
B255749F1BEB6EFC0058F97B /* h2_workers.c */,
B25574A01BEB6EFC0058F97B /* h2_workers.h */,
B25574A11BEB6EFC0058F97B /* m4 */,
B25574A41BEB6EFC0058F97B /* Makefile.am */,
B25574A61BEB6EFC0058F97B /* mod_h2.h */,
B25574A71BEB6EFC0058F97B /* mod_http2.c */,
B2AB9ABC1C2ADBE100908DD6 /* mod_http2.h */,
);
path = mod_http2;
sourceTree = "<group>";
Expand Down
1 change: 0 additions & 1 deletion mod_http2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
*.lo
*.la
.libs
h2_version.h
Makefile.in
Makefile
70 changes: 31 additions & 39 deletions mod_http2/h2_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,58 +204,53 @@ apr_status_t h2_conn_run(struct h2_ctx *ctx, conn_rec *c)

static void fix_event_conn(conn_rec *c, conn_rec *master);

conn_rec *h2_conn_create(conn_rec *master, apr_pool_t *pool)
conn_rec *h2_slave_create(conn_rec *master, apr_pool_t *p,
apr_thread_t *thread, apr_socket_t *socket)
{
conn_rec *c;

AP_DEBUG_ASSERT(master);

ap_log_cerror(APLOG_MARK, APLOG_TRACE3, 0, master,
"h2_conn(%ld): created from master", master->id);

/* This is like the slave connection creation from 2.5-DEV. A
* very efficient way - not sure how compatible this is, since
* the core hooks are no longer run.
* But maybe it's is better this way, not sure yet.
*/
c = (conn_rec *) apr_palloc(pool, sizeof(conn_rec));
c = (conn_rec *) apr_palloc(p, sizeof(conn_rec));
if (c == NULL) {
ap_log_perror(APLOG_MARK, APLOG_ERR, APR_ENOMEM, pool,
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_ENOMEM, master,
APLOGNO(02913) "h2_task: creating conn");
return NULL;
}

memcpy(c, master, sizeof(conn_rec));
c->id = (master->id & (long)pool);
c->master = master;
c->input_filters = NULL;
c->output_filters = NULL;
c->pool = pool;
return c;
}

apr_status_t h2_slave_setup(h2_task *task, apr_bucket_alloc_t *bucket_alloc,
apr_thread_t *thread, apr_socket_t *socket)
{
conn_rec *master = task->mplx->c;

ap_log_perror(APLOG_MARK, APLOG_TRACE3, 0, task->pool,
"h2_conn(%ld): created from master", master->id);

/* Ok, we are just about to start processing the connection and
* the worker is calling us to setup all necessary resources.
* We can borrow some from the worker itself and some we do as
* sub-resources from it, so that we get a nice reuse of
* pools.
*/
task->c->pool = task->pool;
task->c->current_thread = thread;
task->c->bucket_alloc = bucket_alloc;

/* Replace these */
c->id = (master->id & (long)p);
c->master = master;
c->pool = p;
c->current_thread = thread;
c->conn_config = ap_create_conn_config(p);
c->notes = apr_table_make(p, 5);
c->input_filters = NULL;
c->output_filters = NULL;
c->bucket_alloc = apr_bucket_alloc_create(p);
c->cs = NULL;
c->data_in_input_filters = 0;
c->data_in_output_filters = 0;
c->clogging_input_filters = 1;
c->log = NULL;
c->log_id = NULL;

task->c->conn_config = ap_create_conn_config(task->pool);
task->c->notes = apr_table_make(task->pool, 5);
/* TODO: these should be unique to this thread */
c->sbh = master->sbh;

/* In order to do this in 2.4.x, we need to add a member to conn_rec */
task->c->master = master;
/* Simulate that we had already a request on this connection. */
c->keepalives = 1;

ap_set_module_config(task->c->conn_config, &core_module, socket);
ap_set_module_config(c->conn_config, &core_module, socket);

/* This works for mpm_worker so far. Other mpm modules have
* different needs, unfortunately. The most interesting one
Expand All @@ -266,17 +261,14 @@ apr_status_t h2_slave_setup(h2_task *task, apr_bucket_alloc_t *bucket_alloc,
/* all fine */
break;
case H2_MPM_EVENT:
fix_event_conn(task->c, master);
fix_event_conn(c, master);
break;
default:
/* fingers crossed */
break;
}

/* Simulate that we had already a request on this connection. */
task->c->keepalives = 1;

return APR_SUCCESS;
return c;
}

/* This is an internal mpm event.c struct which is disguised
Expand Down
6 changes: 2 additions & 4 deletions mod_http2/h2_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ typedef enum {
h2_mpm_type_t h2_conn_mpm_type(void);


conn_rec *h2_conn_create(conn_rec *master, apr_pool_t *stream_pool);

apr_status_t h2_slave_setup(struct h2_task *task, apr_bucket_alloc_t *bucket_alloc,
apr_thread_t *thread, apr_socket_t *socket);
conn_rec *h2_slave_create(conn_rec *master, apr_pool_t *p,
apr_thread_t *thread, apr_socket_t *socket);

#endif /* defined(__mod_h2__h2_conn__) */
2 changes: 1 addition & 1 deletion mod_http2/h2_h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ static int h2_h2_post_read_req(request_rec *r)
/* setup the correct output filters to process the response
* on the proper mod_http2 way. */
ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, "adding task output filter");
if (task->serialize_headers) {
if (task->ser_headers) {
ap_add_output_filter("H1_TO_H2_RESP", task, r, r->connection);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions mod_http2/h2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
#include "h2_task.h"
#include "h2_util.h"

h2_io *h2_io_create(int id, apr_pool_t *pool, apr_bucket_alloc_t *bucket_alloc)
h2_io *h2_io_create(int id, apr_pool_t *pool)
{
h2_io *io = apr_pcalloc(pool, sizeof(*io));
if (io) {
io->id = id;
io->pool = pool;
io->bucket_alloc = bucket_alloc;
io->bucket_alloc = apr_bucket_alloc_create(pool);
}
return io;
}
Expand Down
2 changes: 1 addition & 1 deletion mod_http2/h2_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct h2_io {
/**
* Creates a new h2_io for the given stream id.
*/
h2_io *h2_io_create(int id, apr_pool_t *pool, apr_bucket_alloc_t *bucket_alloc);
h2_io *h2_io_create(int id, apr_pool_t *pool);

/**
* Frees any resources hold by the h2_io instance.
Expand Down
25 changes: 10 additions & 15 deletions mod_http2/h2_mplx.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ h2_mplx *h2_mplx_create(conn_rec *c, apr_pool_t *parent,
return NULL;
}

m->bucket_alloc = apr_bucket_alloc_create(m->pool);

m->q = h2_tq_create(m->pool, h2_config_geti(conf, H2_CONF_MAX_STREAMS));
m->stream_ios = h2_io_set_create(m->pool);
m->ready_ios = h2_io_set_create(m->pool);
Expand Down Expand Up @@ -266,6 +264,8 @@ apr_status_t h2_mplx_release_and_join(h2_mplx *m, apr_thread_cond_t *wait)
workers_unregister(m);
status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
/* disable WINDOW_UPDATE callbacks */
h2_mplx_set_consumed_cb(m, NULL, NULL);
while (!h2_io_set_iter(m->stream_ios, stream_done_iter, m)) {
/* iterator until all h2_io have been orphaned or destroyed */
}
Expand Down Expand Up @@ -901,15 +901,14 @@ static h2_io *open_io(h2_mplx *m, int stream_id)
m->spare_pool = NULL;
}

io = h2_io_create(stream_id, io_pool, m->bucket_alloc);
io = h2_io_create(stream_id, io_pool);
h2_io_set_add(m->stream_ios, io);

return io;
}


apr_status_t h2_mplx_process(h2_mplx *m, int stream_id,
const h2_request *req, int eos,
apr_status_t h2_mplx_process(h2_mplx *m, int stream_id, const h2_request *req,
h2_stream_pri_cmp *cmp, void *ctx)
{
apr_status_t status;
Expand All @@ -922,9 +921,8 @@ apr_status_t h2_mplx_process(h2_mplx *m, int stream_id,
if (APR_SUCCESS == status) {
h2_io *io = open_io(m, stream_id);
io->request = req;
io->request_body = !eos;

if (eos) {
if (!io->request->body) {
status = h2_io_in_close(io);
}

Expand All @@ -942,9 +940,9 @@ apr_status_t h2_mplx_process(h2_mplx *m, int stream_id,
return status;
}

h2_task *h2_mplx_pop_task(h2_mplx *m, h2_worker *w, int *has_more)
const h2_request *h2_mplx_pop_request(h2_mplx *m, int *has_more)
{
h2_task *task = NULL;
const h2_request *req = NULL;
apr_status_t status;

AP_DEBUG_ASSERT(m);
Expand All @@ -955,18 +953,15 @@ h2_task *h2_mplx_pop_task(h2_mplx *m, h2_worker *w, int *has_more)
status = apr_thread_mutex_lock(m->lock);
if (APR_SUCCESS == status) {
int sid;
while (!task && (sid = h2_tq_shift(m->q)) > 0) {
/* Anything not already setup correctly in the task
* needs to be so now, as task will be executed right about
* when this method returns. */
while (!req && (sid = h2_tq_shift(m->q)) > 0) {
h2_io *io = h2_io_set_get(m->stream_ios, sid);
if (io) {
task = h2_worker_create_task(w, m, io->request, !io->request_body);
req = io->request;
}
}
*has_more = !h2_tq_empty(m->q);
apr_thread_mutex_unlock(m->lock);
}
return task;
return req;
}

8 changes: 2 additions & 6 deletions mod_http2/h2_mplx.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ struct h2_stream;
struct h2_request;
struct h2_io_set;
struct apr_thread_cond_t;
struct h2_worker;
struct h2_workers;
struct h2_stream_set;
struct h2_task_queue;
Expand All @@ -65,7 +64,6 @@ struct h2_mplx {
volatile int refs;
conn_rec *c;
apr_pool_t *pool;
apr_bucket_alloc_t *bucket_alloc;

unsigned int aborted : 1;

Expand Down Expand Up @@ -165,12 +163,10 @@ apr_status_t h2_mplx_out_trywait(h2_mplx *m, apr_interval_time_t timeout,
* @param m the multiplexer
* @param stream_id the identifier of the stream
* @param r the request to be processed
* @param eos if input is complete
* @param cmp the stream priority compare function
* @param ctx context data for the compare function
*/
apr_status_t h2_mplx_process(h2_mplx *m, int stream_id,
const struct h2_request *r, int eos,
apr_status_t h2_mplx_process(h2_mplx *m, int stream_id, const struct h2_request *r,
h2_stream_pri_cmp *cmp, void *ctx);

/**
Expand All @@ -182,7 +178,7 @@ apr_status_t h2_mplx_process(h2_mplx *m, int stream_id,
*/
apr_status_t h2_mplx_reprioritize(h2_mplx *m, h2_stream_pri_cmp *cmp, void *ctx);

struct h2_task *h2_mplx_pop_task(h2_mplx *mplx, struct h2_worker *w, int *has_more);
const struct h2_request *h2_mplx_pop_request(h2_mplx *mplx, int *has_more);

/**
* Register a callback for the amount of input data consumed per stream. The
Expand Down
Loading

0 comments on commit ed46bbf

Please sign in to comment.