# HG changeset patch # User Maxim Dounin # Date 1314355009 -14400 # Node ID 08c660d2db23dace88caad7532d97f8ae812de36 # Parent f3b50effc1d476b040908700bb772197d31fbd80 Keepalive: set_session and save_session callbacks. diff --git a/ngx_http_upstream_keepalive_module.c b/ngx_http_upstream_keepalive_module.c --- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -32,6 +32,11 @@ typedef struct { ngx_event_get_peer_pt original_get_peer; ngx_event_free_peer_pt original_free_peer; +#if (NGX_HTTP_SSL) + ngx_event_set_peer_session_pt original_set_session; + ngx_event_save_peer_session_pt original_save_session; +#endif + ngx_uint_t failed; /* unsigned:1 */ } ngx_http_upstream_keepalive_peer_data_t; @@ -59,6 +64,13 @@ static void ngx_http_upstream_free_keepa static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev); static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev); +#if (NGX_HTTP_SSL) +static ngx_int_t ngx_http_upstream_keepalive_set_session( + ngx_peer_connection_t *pc, void *data); +static void ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, + void *data); +#endif + static void *ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf); static char *ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -182,6 +194,13 @@ ngx_http_upstream_init_keepalive_peer(ng r->upstream->peer.get = ngx_http_upstream_get_keepalive_peer; r->upstream->peer.free = ngx_http_upstream_free_keepalive_peer; +#if (NGX_HTTP_SSL) + kp->original_set_session = r->upstream->peer.set_session; + kp->original_save_session = r->upstream->peer.save_session; + r->upstream->peer.set_session = ngx_http_upstream_keepalive_set_session; + r->upstream->peer.save_session = ngx_http_upstream_keepalive_save_session; +#endif + return NGX_OK; } @@ -423,6 +442,29 @@ close: } +#if (NGX_HTTP_SSL) + +static ngx_int_t +ngx_http_upstream_keepalive_set_session(ngx_peer_connection_t *pc, void *data) +{ + ngx_http_upstream_keepalive_peer_data_t *kp = data; + + return kp->original_set_session(pc, kp->data); +} + + +static void +ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, void *data) +{ + ngx_http_upstream_keepalive_peer_data_t *kp = data; + + kp->original_save_session(pc, kp->data); + return; +} + +#endif + + static void * ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf) { # HG changeset patch # User Maxim Dounin # Date 1314372266 -14400 # Node ID 858bbe1d2ec49193919a851aba22507f503bb210 # Parent 08c660d2db23dace88caad7532d97f8ae812de36 Keepalive: handle separaate pool for upstream connections. Make sure to set c->pool->log properly, and destroy pool while closing connection. diff --git a/ngx_http_upstream_keepalive_module.c b/ngx_http_upstream_keepalive_module.c --- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -236,6 +236,7 @@ ngx_http_upstream_get_keepalive_peer(ngx c->log = pc->log; c->read->log = pc->log; c->write->log = pc->log; + c->pool->log = pc->log; pc->connection = c; pc->cached = 1; @@ -271,6 +272,7 @@ ngx_http_upstream_get_keepalive_peer(ngx c->log = pc->log; c->read->log = pc->log; c->write->log = pc->log; + c->pool->log = pc->log; pc->connection = c; pc->cached = 1; @@ -353,6 +355,7 @@ ngx_http_upstream_free_keepalive_peer(ng item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); + ngx_destroy_pool(item->connection->pool); ngx_close_connection(item->connection); } else { @@ -383,6 +386,7 @@ ngx_http_upstream_free_keepalive_peer(ng c->log = ngx_cycle->log; c->read->log = ngx_cycle->log; c->write->log = ngx_cycle->log; + c->pool->log = ngx_cycle->log; item->socklen = pc->socklen; ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen); @@ -437,6 +441,7 @@ close: conf = item->conf; ngx_queue_remove(&item->queue); + ngx_destroy_pool(item->connection->pool); ngx_close_connection(item->connection); ngx_queue_insert_head(&conf->free, &item->queue); } # HG changeset patch # User Maxim Dounin # Date 1314372548 -14400 # Node ID b8bdd973dcfbda97f54c27986fdf7e0894c21c39 # Parent 858bbe1d2ec49193919a851aba22507f503bb210 Keepalive: properly close ssl connections. diff --git a/ngx_http_upstream_keepalive_module.c b/ngx_http_upstream_keepalive_module.c --- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -63,6 +63,8 @@ static void ngx_http_upstream_free_keepa static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev); static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev); +static void ngx_http_upstream_keepalive_close(ngx_connection_t *c); + #if (NGX_HTTP_SSL) static ngx_int_t ngx_http_upstream_keepalive_set_session( @@ -355,8 +357,7 @@ ngx_http_upstream_free_keepalive_peer(ng item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); - ngx_destroy_pool(item->connection->pool); - ngx_close_connection(item->connection); + ngx_http_upstream_keepalive_close(item->connection); } else { q = ngx_queue_head(&kp->conf->free); @@ -440,13 +441,33 @@ close: item = c->data; conf = item->conf; + ngx_http_upstream_keepalive_close(c); + ngx_queue_remove(&item->queue); - ngx_destroy_pool(item->connection->pool); - ngx_close_connection(item->connection); ngx_queue_insert_head(&conf->free, &item->queue); } +static void +ngx_http_upstream_keepalive_close(ngx_connection_t *c) +{ + +#if (NGX_HTTP_SSL) + + if (c->ssl) { + c->ssl->no_wait_shutdown = 1; + c->ssl->no_send_shutdown = 1; + + (void) ngx_ssl_shutdown(c); + } + +#endif + + ngx_destroy_pool(c->pool); + ngx_close_connection(c); +} + + #if (NGX_HTTP_SSL) static ngx_int_t