Skip to content

Commit 4577a6f

Browse files
spacewanderagentzh
authored andcommitted
bugfix: freed all connections when cleaning up socket pools.
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 4e1a9e1 commit 4577a6f

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/ngx_http_lua_socket_tcp.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ static ngx_int_t ngx_http_lua_get_keepalive_peer(ngx_http_request_t *r,
101101
static void ngx_http_lua_socket_keepalive_dummy_handler(ngx_event_t *ev);
102102
static ngx_int_t ngx_http_lua_socket_keepalive_close_handler(ngx_event_t *ev);
103103
static void ngx_http_lua_socket_keepalive_rev_handler(ngx_event_t *ev);
104-
static void ngx_http_lua_socket_free_pool(ngx_log_t *log,
105-
ngx_http_lua_socket_pool_t *spool);
106104
static int ngx_http_lua_socket_tcp_upstream_destroy(lua_State *L);
107105
static int ngx_http_lua_socket_downstream_destroy(lua_State *L);
108106
static ngx_int_t ngx_http_lua_socket_push_input_data(ngx_http_request_t *r,
@@ -122,7 +120,11 @@ static ngx_int_t ngx_http_lua_socket_tcp_resume_helper(ngx_http_request_t *r,
122120
int socket_op);
123121
static void ngx_http_lua_tcp_resolve_cleanup(void *data);
124122
static void ngx_http_lua_coctx_cleanup(void *data);
123+
static void ngx_http_lua_socket_free_pool(ngx_log_t *log,
124+
ngx_http_lua_socket_pool_t *spool);
125125
static int ngx_http_lua_socket_shutdown_pool(lua_State *L);
126+
static void ngx_http_lua_socket_shutdown_pool_helper(
127+
ngx_http_lua_socket_pool_t *spool);
126128
static void
127129
ngx_http_lua_socket_empty_resolve_handler(ngx_resolver_ctx_t *ctx);
128130
static int ngx_http_lua_socket_prepare_error_retvals(ngx_http_request_t *r,
@@ -5009,19 +5011,13 @@ ngx_http_lua_socket_free_pool(ngx_log_t *log, ngx_http_lua_socket_pool_t *spool)
50095011
}
50105012

50115013

5012-
static int
5013-
ngx_http_lua_socket_shutdown_pool(lua_State *L)
5014+
static void
5015+
ngx_http_lua_socket_shutdown_pool_helper(ngx_http_lua_socket_pool_t *spool)
50145016
{
50155017
ngx_queue_t *q;
50165018
ngx_connection_t *c;
5017-
ngx_http_lua_socket_pool_t *spool;
50185019
ngx_http_lua_socket_pool_item_t *item;
50195020

5020-
spool = lua_touserdata(L, 1);
5021-
if (spool == NULL) {
5022-
return 0;
5023-
}
5024-
50255021
while (!ngx_queue_empty(&spool->cache)) {
50265022
q = ngx_queue_head(&spool->cache);
50275023

@@ -5035,6 +5031,19 @@ ngx_http_lua_socket_shutdown_pool(lua_State *L)
50355031
}
50365032

50375033
spool->active_connections = 0;
5034+
}
5035+
5036+
5037+
static int
5038+
ngx_http_lua_socket_shutdown_pool(lua_State *L)
5039+
{
5040+
ngx_http_lua_socket_pool_t *spool;
5041+
5042+
spool = lua_touserdata(L, 1);
5043+
5044+
if (spool != NULL) {
5045+
ngx_http_lua_socket_shutdown_pool_helper(spool);
5046+
}
50385047

50395048
return 0;
50405049
}
@@ -5451,10 +5460,7 @@ ngx_http_lua_ssl_free_session(lua_State *L)
54515460
void
54525461
ngx_http_lua_cleanup_conn_pools(lua_State *L)
54535462
{
5454-
ngx_queue_t *q;
5455-
ngx_connection_t *c;
54565463
ngx_http_lua_socket_pool_t *spool;
5457-
ngx_http_lua_socket_pool_item_t *item;
54585464

54595465
lua_pushlightuserdata(L, &ngx_http_lua_socket_pool_key);
54605466
lua_rawget(L, LUA_REGISTRYINDEX); /* table */
@@ -5464,18 +5470,12 @@ ngx_http_lua_cleanup_conn_pools(lua_State *L)
54645470
/* tb key val */
54655471
spool = lua_touserdata(L, -1);
54665472

5467-
if (!ngx_queue_empty(&spool->cache)) {
5468-
q = ngx_queue_head(&spool->cache);
5469-
item = ngx_queue_data(q, ngx_http_lua_socket_pool_item_t, queue);
5470-
c = item->connection;
5471-
5472-
ngx_http_lua_socket_tcp_close_connection(c);
5473-
5474-
ngx_queue_remove(q);
5473+
if (spool != NULL) {
5474+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
5475+
"lua tcp socket keepalive: free connection pool %p "
5476+
"for \"%s\"", spool, spool->key);
54755477

5476-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
5477-
"lua tcp socket keepalive: free connection pool "
5478-
"for \"%s\"", spool->key);
5478+
ngx_http_lua_socket_shutdown_pool_helper(spool);
54795479
}
54805480

54815481
lua_pop(L, 1);

0 commit comments

Comments
 (0)