From 4679522dde0b9744e71678ab8e6af1e4d7063c12 Mon Sep 17 00:00:00 2001 From: Ashley Moravek Date: Mon, 13 Jun 2016 07:05:25 +0200 Subject: [PATCH 1/2] Allow both upsyncs at once --- src/ngx_stream_upsync_module.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ngx_stream_upsync_module.c b/src/ngx_stream_upsync_module.c index cf6a88f..363af73 100644 --- a/src/ngx_stream_upsync_module.c +++ b/src/ngx_stream_upsync_module.c @@ -254,8 +254,8 @@ static http_parser_settings settings = { .on_message_complete = 0 }; -ngx_atomic_t upsync_shared_created0; -ngx_atomic_t *upsync_shared_created = &upsync_shared_created0; +ngx_atomic_t stream_upsync_shared_created0; +ngx_atomic_t *stream_upsync_shared_created = &stream_upsync_shared_created0; static http_parser *parser = NULL; static ngx_stream_http_state state; @@ -1913,10 +1913,10 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle) upsync_server = upsync_ctx->upsync_server; - if (*upsync_shared_created) { - shm.size = 128 * (*upsync_shared_created); + if (*stream_upsync_shared_created) { + shm.size = 128 * (*stream_upsync_shared_created); shm.log = cycle->log; - shm.addr = (u_char *)(upsync_shared_created); + shm.addr = (u_char *)(stream_upsync_shared_created); shm.name.len = sizeof("ngx_upsync_shared_zone"); shm.name.data = (u_char *)"ngx_upsync_shared_zone"; @@ -1942,7 +1942,7 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle) } shared = shm.addr; - upsync_shared_created = (ngx_atomic_t *)shared; + stream_upsync_shared_created = (ngx_atomic_t *)shared; for (i = 0; i < upsync_ctx->upstream_num; i++) { @@ -1970,7 +1970,7 @@ ngx_stream_upsync_init_shm_mutex(ngx_cycle_t *cycle) } } - ngx_atomic_cmp_set(upsync_shared_created, *upsync_shared_created, + ngx_atomic_cmp_set(stream_upsync_shared_created, *stream_upsync_shared_created, upsync_ctx->upstream_num); return NGX_OK; From 0d78b654125ea0e865891037b761a75f225e4211 Mon Sep 17 00:00:00 2001 From: Ashley Moravek Date: Mon, 13 Jun 2016 07:20:08 +0200 Subject: [PATCH 2/2] Do not crash if no stream {} block is defined --- src/ngx_stream_upsync_module.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ngx_stream_upsync_module.c b/src/ngx_stream_upsync_module.c index 363af73..f5a09bd 100644 --- a/src/ngx_stream_upsync_module.c +++ b/src/ngx_stream_upsync_module.c @@ -1878,7 +1878,12 @@ ngx_stream_upsync_init_module(ngx_cycle_t *cycle) ngx_uint_t i; ngx_stream_upsync_server_t *upsync_server; ngx_stream_upsync_srv_conf_t *upscf; - + + // no stream {} block found + if (upsync_ctx == NULL) { + return NGX_OK; + } + upsync_server = upsync_ctx->upsync_server; if (ngx_stream_upsync_init_shm_mutex(cycle) != NGX_OK) { @@ -1988,6 +1993,10 @@ ngx_stream_upsync_init_process(ngx_cycle_t *cycle) ngx_stream_upsync_ctx_t *ctx; ngx_stream_upsync_server_t *upsync_server; + // no stream {} block found + if (upsync_ctx == NULL) { + return NGX_OK; + } upsync_server = upsync_ctx->upsync_server; for (i = 0; i < upsync_ctx->upstream_num; i++) {