aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-29 14:04:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-29 14:04:07 +0100
commit35c1a939f4cab0738e43610a6b4d740b08ad0531 (patch)
tree58d666a7b50181b811b98d7529cd7af7c49b9564
parent47fc9abba0782b57dbaa2ab5aa32ab7dea43d3af (diff)
downloadrspamd-35c1a939f4cab0738e43610a6b4d740b08ad0531.tar.gz
rspamd-35c1a939f4cab0738e43610a6b4d740b08ad0531.zip
[Fix] Further tweaks to redis garbadge collection
-rw-r--r--src/lua/lua_redis.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index 016660b8f..68e659d84 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -304,6 +304,7 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv)
struct lua_redis_specific_userdata *sp_ud = priv;
struct lua_redis_ctx *ctx;
struct lua_redis_userdata *ud;
+ redisAsyncContext *ac;
ctx = sp_ud->ctx;
ud = sp_ud->c;
@@ -314,6 +315,7 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv)
}
event_del (&sp_ud->timeout);
+ ctx->cmds_pending --;
if (c->err == 0) {
if (r != NULL) {
@@ -336,6 +338,14 @@ lua_redis_callback (redisAsyncContext *c, gpointer r, gpointer priv)
lua_redis_push_error (c->errstr, ctx, sp_ud, TRUE);
}
}
+
+ if (ctx->cmds_pending == 0) {
+ /* Disconnect redis early as we don't need it anymore */
+ ud->terminated = 1;
+ ac = ud->ctx;
+ ud->ctx = NULL;
+ redisAsyncFree (ac);
+ }
}
static void
@@ -645,6 +655,7 @@ lua_redis_make_request (lua_State *L)
sp_ud->ctx = ctx;
REF_RETAIN (ctx);
+ ctx->cmds_pending ++;
double_to_tv (timeout, &tv);
event_set (&sp_ud->timeout, -1, EV_TIMEOUT, lua_redis_timeout, sp_ud);
event_base_set (ud->task->ev_base, &sp_ud->timeout);
@@ -1054,6 +1065,7 @@ lua_redis_add_cmd (lua_State *L)
event_base_set (sp_ud->c->task->ev_base, &sp_ud->timeout);
event_add (&sp_ud->timeout, &tv);
REF_RETAIN (ctx);
+ ctx->cmds_pending ++;
}
else {
msg_info ("call to redis failed: %s", sp_ud->c->ctx->errstr);